summaryrefslogtreecommitdiff
path: root/src/Propellor/Types.hs
diff options
context:
space:
mode:
authorJoey Hess2014-05-31 20:39:56 -0400
committerJoey Hess2014-05-31 20:43:23 -0400
commit4f70fceb3a79f2c2b746407768faf363d11c11a4 (patch)
tree3f0c05ed545b761bbe3f07576d1ef0259a48c4af /src/Propellor/Types.hs
parent6b835c5eeb352718a11e707a0e10d2bc5092782b (diff)
got rid of the Attr -> Attr SetAttr hack, and use monoids for Attr
The SetAttr hack used to be needed because the hostname was part of the Attr, and was required to be present. Now that it's moved to Host, let's get rid of that, since it tended to waste CPU.
Diffstat (limited to 'src/Propellor/Types.hs')
-rw-r--r--src/Propellor/Types.hs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/Propellor/Types.hs b/src/Propellor/Types.hs
index a96e9520..e0d471ff 100644
--- a/src/Propellor/Types.hs
+++ b/src/Propellor/Types.hs
@@ -4,14 +4,13 @@
module Propellor.Types
( Host(..)
, Attr
- , SetAttr
+ , getAttr
, Propellor(..)
, Property(..)
, RevertableProperty(..)
, IsProp
, describe
, toProp
- , setAttr
, requires
, Desc
, Result(..)
@@ -39,7 +38,7 @@ import Propellor.Types.Dns
data Host = Host
{ _hostName :: HostName
, _hostProps :: [Property]
- , _hostAttrs :: SetAttr
+ , _hostAttr :: Attr
}
-- | Propellor's monad provides read-only access to the host it's running
@@ -61,8 +60,8 @@ data Property = Property
{ propertyDesc :: Desc
, propertySatisfy :: Propellor Result
-- ^ must be idempotent; may run repeatedly
- , propertyAttr :: SetAttr
- -- ^ a property can set an Attr on the host that has the property.
+ , propertyAttr :: Attr
+ -- ^ a property can set an attribute of the host that has the property.
}
-- | A property that can be reverted.
@@ -75,15 +74,15 @@ class IsProp p where
-- | Indicates that the first property can only be satisfied
-- once the second one is.
requires :: p -> Property -> p
- setAttr :: p -> SetAttr
+ getAttr :: p -> Attr
instance IsProp Property where
describe p d = p { propertyDesc = d }
toProp p = p
- setAttr = propertyAttr
+ getAttr = propertyAttr
x `requires` y = Property (propertyDesc x) satisfy attr
where
- attr = propertyAttr x . propertyAttr y
+ attr = getAttr y <> getAttr x
satisfy = do
r <- propertySatisfy y
case r of
@@ -98,8 +97,8 @@ instance IsProp RevertableProperty where
toProp (RevertableProperty p1 _) = p1
(RevertableProperty p1 p2) `requires` y =
RevertableProperty (p1 `requires` y) p2
- -- | Return the SetAttr of the currently active side.
- setAttr (RevertableProperty p1 _p2) = setAttr p1
+ -- | Return the Attr of the currently active side.
+ getAttr (RevertableProperty p1 _p2) = getAttr p1
type Desc = String