summaryrefslogtreecommitdiff
path: root/src/Propellor/Types
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor/Types')
-rw-r--r--src/Propellor/Types/Info.hs13
-rw-r--r--src/Propellor/Types/PrivData.hs2
2 files changed, 12 insertions, 3 deletions
diff --git a/src/Propellor/Types/Info.hs b/src/Propellor/Types/Info.hs
index a80bb681..347a03e7 100644
--- a/src/Propellor/Types/Info.hs
+++ b/src/Propellor/Types/Info.hs
@@ -5,6 +5,7 @@ module Propellor.Types.Info (
IsInfo(..),
addInfo,
getInfo,
+ mapInfo,
propigatableInfo,
InfoVal(..),
fromInfoVal,
@@ -16,8 +17,6 @@ import Data.Monoid
import Data.Maybe
-- | Information about a Host, which can be provided by its properties.
---
--- Any value in the `IsInfo` type class can be added to an Info.
data Info = Info [(Dynamic, Bool)]
instance Show Info where
@@ -37,12 +36,22 @@ class (Typeable v, Monoid v) => IsInfo v where
-- container to its Host?
propigateInfo :: v -> Bool
+-- | Any value in the `IsInfo` type class can be added to an Info.
addInfo :: IsInfo v => Info -> v -> Info
addInfo (Info l) v = Info ((toDyn v, propigateInfo v):l)
getInfo :: IsInfo v => Info -> v
getInfo (Info l) = mconcat (mapMaybe (fromDynamic . fst) (reverse l))
+-- | Maps a function over all values stored in the Info that are of the
+-- appropriate type.
+mapInfo :: IsInfo v => (v -> v) -> Info -> Info
+mapInfo f (Info l) = Info (map go l)
+ where
+ go (i, p) = case fromDynamic i of
+ Nothing -> (i, p)
+ Just v -> (toDyn (f v), p)
+
-- | Filters out parts of the Info that should not propigate out of a
-- container.
propigatableInfo :: Info -> Info
diff --git a/src/Propellor/Types/PrivData.hs b/src/Propellor/Types/PrivData.hs
index 98cdb7a1..1cf22aa9 100644
--- a/src/Propellor/Types/PrivData.hs
+++ b/src/Propellor/Types/PrivData.hs
@@ -61,7 +61,7 @@ instance IsPrivDataSource PrivDataSource where
newtype Context = Context String
deriving (Read, Show, Ord, Eq)
--- | A context that varies depending on the HostName where it's used.
+-- | A context that may vary depending on the HostName where it's used.
newtype HostContext = HostContext { mkHostContext :: HostName -> Context }
instance Show HostContext where