etc-0.3.2.0: Declarative configuration spec for Haskell projects

Safe HaskellNone
LanguageHaskell2010

System.Etc.Internal.Types

Documentation

data Value a Source #

Constructors

Plain 

Fields

Sensitive 

Fields

Instances

Functor Value Source # 

Methods

fmap :: (a -> b) -> Value a -> Value b #

(<$) :: a -> Value b -> Value a #

Applicative Value Source # 

Methods

pure :: a -> Value a #

(<*>) :: Value (a -> b) -> Value a -> Value b #

liftA2 :: (a -> b -> c) -> Value a -> Value b -> Value c #

(*>) :: Value a -> Value b -> Value b #

(<*) :: Value a -> Value b -> Value a #

Eq a => Eq (Value a) Source # 

Methods

(==) :: Value a -> Value a -> Bool #

(/=) :: Value a -> Value a -> Bool #

Ord a => Ord (Value a) Source # 

Methods

compare :: Value a -> Value a -> Ordering #

(<) :: Value a -> Value a -> Bool #

(<=) :: Value a -> Value a -> Bool #

(>) :: Value a -> Value a -> Bool #

(>=) :: Value a -> Value a -> Bool #

max :: Value a -> Value a -> Value a #

min :: Value a -> Value a -> Value a #

Show a => Show (Value a) Source # 

Methods

showsPrec :: Int -> Value a -> ShowS #

show :: Value a -> String #

showList :: [Value a] -> ShowS #

IsString a => IsString (Value a) Source # 

Methods

fromString :: String -> Value a #

Generic (Value a) Source # 

Associated Types

type Rep (Value a) :: * -> * #

Methods

from :: Value a -> Rep (Value a) x #

to :: Rep (Value a) x -> Value a #

type Rep (Value a) Source # 
type Rep (Value a) = D1 * (MetaData "Value" "System.Etc.Internal.Types" "etc-0.3.2.0-3AoZaWPWVK6J23hvl2CaKC" False) ((:+:) * (C1 * (MetaCons "Plain" PrefixI True) (S1 * (MetaSel (Just Symbol "fromValue") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * a))) (C1 * (MetaCons "Sensitive" PrefixI True) (S1 * (MetaSel (Just Symbol "fromValue") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * a))))

filterMaybe :: (a -> Bool) -> Maybe a -> Maybe a Source #

class IConfig config where Source #

Methods

getConfigValue Source #

Arguments

:: (MonadThrow m, FromJSON result) 
=> [Text]

Key to fetch from config map

-> config

Config record

-> m result 

Fetches a configuration value from a given key, if key is not found, you may pick the failure mode via the MonadThrow interface.

example:

>>> getConfigValue ["db", "user"] config :: Maybe Text
Just "root"
>>> getConfigValue ["db", "password"] config :: Maybe Text
Nothing

getConfigValueWith Source #

Arguments

:: MonadThrow m 
=> (Value -> Parser result)

JSON Parser function

-> [Text]

Key to fetch from config map

-> config

Config record

-> m result 

Fetches a configuration value from a given key, normally this key will point to a sub-config JSON object, which is then passed to the given JSON parser function. If key is not found, you may pick the failure mode via the MonadThrow interface.

example:

>>> import qualified Data.Aeson as JSON
>>> import qualified Data.Aeson.Types as JSON (Parser)
>>> connectInfoParser :: JSON.Value -> JSON.Parser DbConnectInfo
>>> getConfigValueWith connectInfoParser ["db"] config
Just (DbConnectInfo {...})

getAllConfigSources :: MonadThrow m => [Text] -> config -> m (Set ConfigSource) Source #

getSelectedConfigSource :: MonadThrow m => [Text] -> config -> m ConfigSource Source #