module Propellor.PropAccum
( host
, props
, PropAccum(..)
, (!)
, PropList
, propigateContainer
) where
import Data.Monoid
import Propellor.Types
import Propellor.Property
host :: HostName -> Host
host hn = Host hn [] mempty
props :: PropList
props = PropList []
class PropAccum h where
(&) :: IsProp p => h -> p -> h
(&^) :: IsProp p => h -> p -> h
getProperties :: h -> [Property HasInfo]
instance PropAccum Host where
(Host hn ps is) & p = Host hn (ps ++ [toProp p])
(is <> getInfoRecursive p)
(Host hn ps is) &^ p = Host hn ([toProp p] ++ ps)
(getInfoRecursive p <> is)
getProperties = hostProperties
data PropList = PropList [Property HasInfo]
instance PropAccum PropList where
PropList l & p = PropList (toProp p : l)
PropList l &^ p = PropList (l ++ [toProp p])
getProperties (PropList l) = reverse l
(!) :: PropAccum h => h -> RevertableProperty -> h
h ! p = h & revert p
infixl 1 &^
infixl 1 &
infixl 1 !
propigateContainer
:: (PropAccum container)
=> container
-> Property HasInfo
-> Property HasInfo
propigateContainer c prop = infoProperty
(propertyDesc prop)
(propertySatisfy prop)
(propertyInfo prop)
(propertyChildren prop ++ hostprops)
where
hostprops = map go $ getProperties c
go p =
let i = propertyInfo p
i' = mempty
{ _dns = _dns i
, _privData = _privData i
}
cs = map go (propertyChildren p)
in infoProperty (propertyDesc p) (propertySatisfy p) i' cs