module Propellor.PropAccum
( host
, PropAccum(..)
, (&)
, (&^)
, (!)
, propagateContainer
) where
import Data.Monoid
import Propellor.Types
import Propellor.Property
import Propellor.Types.Info
import Propellor.PrivData
host :: HostName -> Host
host hn = Host hn [] mempty
class PropAccum h where
addProp :: IsProp p => h -> p -> h
addPropFront :: IsProp p => h -> p -> h
getProperties :: h -> [Property HasInfo]
(&) :: (PropAccum h, IsProp p) => h -> p -> h
(&) = addProp
(&^) :: (PropAccum h, IsProp p) => h -> p -> h
(&^) = addPropFront
(!) :: IsProp (RevertableProperty i) => PropAccum h => h -> RevertableProperty i -> h
h ! p = h & revert p
infixl 1 &
infixl 1 &^
infixl 1 !
instance PropAccum Host where
(Host hn ps is) `addProp` p = Host hn (ps ++ [toProp p])
(is <> getInfoRecursive p)
(Host hn ps is) `addPropFront` p = Host hn (toProp p : ps)
(getInfoRecursive p <> is)
getProperties = hostProperties
propagateContainer
:: (PropAccum container)
=> String
-> container
-> Property HasInfo
-> Property HasInfo
propagateContainer containername c prop = infoProperty
(propertyDesc prop)
(propertySatisfy prop)
(propertyInfo prop)
(propertyChildren prop ++ hostprops)
where
hostprops = map go $ getProperties c
go p =
let i = mapInfo (forceHostContext containername)
(propagatableInfo (propertyInfo p))
cs = map go (propertyChildren p)
in infoProperty (propertyDesc p) (propertySatisfy p) i cs