salak-0.3.5.2: Configuration (re)Loader and Parser.

Copyright2019 Daniel YU
LicenseMIT
Maintainerleptonyu@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Salak.Internal

Contents

Description

This module is used for implementing loaders.

Synopsis

Documentation

loadAndRunSalak' :: (MonadThrow m, MonadIO m) => LoadSalakT m () -> (SourcePack -> m a) -> m a Source #

Standard salak functions, by load and with a SourcePack instance. Users should use SourcePack to create custom MonadSalak instances, then you get will an instance of MonadSalak.

loadAndRunSalak :: (MonadThrow m, MonadIO m) => LoadSalakT m () -> RunSalakT m a -> m a Source #

Standard salak functions, by load and run with RunSalakT.

loadTrie :: (MonadThrow m, MonadIO m) => Bool -> String -> (Int -> IO TraceSource) -> LoadSalakT m () Source #

Basic loader

loadList :: (MonadThrow m, MonadIO m, Foldable f, ToKeys k, ToValue v) => Bool -> String -> IO (f (k, v)) -> LoadSalakT m () Source #

Simple loader

data LoadSalakT m a Source #

Configuration Loader Monad, used for load properties from sources. Custom loaders using loadTrie

Instances
MonadTrans LoadSalakT Source # 
Instance details

Defined in Salak.Internal

Methods

lift :: Monad m => m a -> LoadSalakT m a #

Monad m => Monad (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

(>>=) :: LoadSalakT m a -> (a -> LoadSalakT m b) -> LoadSalakT m b #

(>>) :: LoadSalakT m a -> LoadSalakT m b -> LoadSalakT m b #

return :: a -> LoadSalakT m a #

fail :: String -> LoadSalakT m a #

Functor m => Functor (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

fmap :: (a -> b) -> LoadSalakT m a -> LoadSalakT m b #

(<$) :: a -> LoadSalakT m b -> LoadSalakT m a #

Monad m => Applicative (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

pure :: a -> LoadSalakT m a #

(<*>) :: LoadSalakT m (a -> b) -> LoadSalakT m a -> LoadSalakT m b #

liftA2 :: (a -> b -> c) -> LoadSalakT m a -> LoadSalakT m b -> LoadSalakT m c #

(*>) :: LoadSalakT m a -> LoadSalakT m b -> LoadSalakT m b #

(<*) :: LoadSalakT m a -> LoadSalakT m b -> LoadSalakT m a #

MonadIO m => MonadIO (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

liftIO :: IO a -> LoadSalakT m a #

MonadThrow m => MonadThrow (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

throwM :: Exception e => e -> LoadSalakT m a #

MonadCatch m => MonadCatch (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

catch :: Exception e => LoadSalakT m a -> (e -> LoadSalakT m a) -> LoadSalakT m a #

(MonadThrow m, MonadUnliftIO m) => MonadUnliftIO (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

askUnliftIO :: LoadSalakT m (UnliftIO (LoadSalakT m)) #

withRunInIO :: ((forall a. LoadSalakT m a -> IO a) -> IO b) -> LoadSalakT m b #

MonadIO m => MonadSalak (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

type LoadSalak = LoadSalakT IO Source #

Simple IO Monad

data RunSalakT m a Source #

Standard MonadSalak instance.

Instances
MonadTrans RunSalakT Source # 
Instance details

Defined in Salak.Internal

Methods

lift :: Monad m => m a -> RunSalakT m a #

Monad m => MonadReader SourcePack (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

ask :: RunSalakT m SourcePack #

local :: (SourcePack -> SourcePack) -> RunSalakT m a -> RunSalakT m a #

reader :: (SourcePack -> a) -> RunSalakT m a #

Monad m => Monad (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

(>>=) :: RunSalakT m a -> (a -> RunSalakT m b) -> RunSalakT m b #

(>>) :: RunSalakT m a -> RunSalakT m b -> RunSalakT m b #

return :: a -> RunSalakT m a #

fail :: String -> RunSalakT m a #

Functor m => Functor (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

fmap :: (a -> b) -> RunSalakT m a -> RunSalakT m b #

(<$) :: a -> RunSalakT m b -> RunSalakT m a #

Applicative m => Applicative (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

pure :: a -> RunSalakT m a #

(<*>) :: RunSalakT m (a -> b) -> RunSalakT m a -> RunSalakT m b #

liftA2 :: (a -> b -> c) -> RunSalakT m a -> RunSalakT m b -> RunSalakT m c #

(*>) :: RunSalakT m a -> RunSalakT m b -> RunSalakT m b #

(<*) :: RunSalakT m a -> RunSalakT m b -> RunSalakT m a #

MonadIO m => MonadIO (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

liftIO :: IO a -> RunSalakT m a #

MonadThrow m => MonadThrow (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

throwM :: Exception e => e -> RunSalakT m a #

MonadCatch m => MonadCatch (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

catch :: Exception e => RunSalakT m a -> (e -> RunSalakT m a) -> RunSalakT m a #

(MonadThrow m, MonadUnliftIO m) => MonadUnliftIO (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

askUnliftIO :: RunSalakT m (UnliftIO (RunSalakT m)) #

withRunInIO :: ((forall a. RunSalakT m a -> IO a) -> IO b) -> RunSalakT m b #

MonadIO m => MonadSalak (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

type RunSalak = RunSalakT IO Source #

Simple IO Monad

class Monad m => MonadSalak m where Source #

Core type class of salak, which provide function to parse properties.

Minimal complete definition

askSourcePack

Methods

askSourcePack :: m SourcePack Source #

Monad has the ability to get a SourcePack instance.

askReload :: m (IO ReloadResult) Source #

Get reload action which used for reload profiles

setLogF :: MonadIO m => (CallStack -> Text -> IO ()) -> m () Source #

logSalak :: (HasCallStack, MonadIO m) => Text -> m () Source #

require :: (MonadThrow m, MonadIO m, FromProp m a) => Text -> m a Source #

Parse properties using FromProp. For example:

a :: Bool              <- require "bool.key"
b :: Maybe Int         <- require "int.optional.key"
c :: Either String Int <- require "int.error.key"
d :: IO Int            <- require "int.reloadable.key"

require supports parse IO values, which actually wrap a MVar variable and can be reseted by reloading configurations. Normal value will not be affected by reloading configurations.

loadMock :: (MonadThrow m, MonadIO m) => [(Text, Text)] -> LoadSalakT m () Source #

Load mock variables into Source

loadEnv :: (MonadThrow m, MonadIO m) => LoadSalakT m () Source #

Load environment variables into Source

loadCommandLine :: (MonadThrow m, MonadIO m) => ParseCommandLine -> LoadSalakT m () Source #

Default way to parse command line arguments

type ParseCommandLine = [String] -> IO [(Text, Text)] Source #

Convert arguments to properties

defaultParseCommandLine :: ParseCommandLine Source #

Default way to parse command line arguments

tryLoadFile :: MonadIO m => (FilePath -> LoadSalakT m ()) -> FilePath -> LoadSalakT m () Source #

Try load file, if file does not exist then do nothing.

type Source = Trie Vals Source #

type TraceSource = Trie TraceVals Source #

newtype Keys Source #

Constructors

Keys 

Fields

Instances
Eq Keys Source # 
Instance details

Defined in Salak.Internal.Key

Methods

(==) :: Keys -> Keys -> Bool #

(/=) :: Keys -> Keys -> Bool #

Ord Keys Source # 
Instance details

Defined in Salak.Internal.Key

Methods

compare :: Keys -> Keys -> Ordering #

(<) :: Keys -> Keys -> Bool #

(<=) :: Keys -> Keys -> Bool #

(>) :: Keys -> Keys -> Bool #

(>=) :: Keys -> Keys -> Bool #

max :: Keys -> Keys -> Keys #

min :: Keys -> Keys -> Keys #

Show Keys Source # 
Instance details

Defined in Salak.Internal.Key

Methods

showsPrec :: Int -> Keys -> ShowS #

show :: Keys -> String #

showList :: [Keys] -> ShowS #

IsString Keys Source # 
Instance details

Defined in Salak.Internal.Key

Methods

fromString :: String -> Keys #

Semigroup Keys Source # 
Instance details

Defined in Salak.Internal.Key

Methods

(<>) :: Keys -> Keys -> Keys #

sconcat :: NonEmpty Keys -> Keys #

stimes :: Integral b => b -> Keys -> Keys #

Monoid Keys Source # 
Instance details

Defined in Salak.Internal.Key

Methods

mempty :: Keys #

mappend :: Keys -> Keys -> Keys #

mconcat :: [Keys] -> Keys #

ToKeys Keys Source # 
Instance details

Defined in Salak.Internal.Key

data Key Source #

Constructors

KT !Text 
KI !Int 
Instances
Eq Key Source # 
Instance details

Defined in Salak.Internal.Key

Methods

(==) :: Key -> Key -> Bool #

(/=) :: Key -> Key -> Bool #

Ord Key Source # 
Instance details

Defined in Salak.Internal.Key

Methods

compare :: Key -> Key -> Ordering #

(<) :: Key -> Key -> Bool #

(<=) :: Key -> Key -> Bool #

(>) :: Key -> Key -> Bool #

(>=) :: Key -> Key -> Bool #

max :: Key -> Key -> Key #

min :: Key -> Key -> Key #

Show Key Source # 
Instance details

Defined in Salak.Internal.Key

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String #

showList :: [Key] -> ShowS #

Hashable Key Source # 
Instance details

Defined in Salak.Internal.Key

Methods

hashWithSalt :: Int -> Key -> Int #

hash :: Key -> Int #

class ToKeys a where Source #

Methods

toKeys :: a -> Either String Keys Source #

Instances
ToKeys String Source # 
Instance details

Defined in Salak.Internal.Key

ToKeys Text Source # 
Instance details

Defined in Salak.Internal.Key

ToKeys Keys Source # 
Instance details

Defined in Salak.Internal.Key

data Val v Source #

Constructors

Val !Int !v 
Instances
Eq v => Eq (Val v) Source # 
Instance details

Defined in Salak.Internal.Val

Methods

(==) :: Val v -> Val v -> Bool #

(/=) :: Val v -> Val v -> Bool #

Eq v => Ord (Val v) Source # 
Instance details

Defined in Salak.Internal.Val

Methods

compare :: Val v -> Val v -> Ordering #

(<) :: Val v -> Val v -> Bool #

(<=) :: Val v -> Val v -> Bool #

(>) :: Val v -> Val v -> Bool #

(>=) :: Val v -> Val v -> Bool #

max :: Val v -> Val v -> Val v #

min :: Val v -> Val v -> Val v #

Show v => Show (Val v) Source # 
Instance details

Defined in Salak.Internal.Val

Methods

showsPrec :: Int -> Val v -> ShowS #

show :: Val v -> String #

showList :: [Val v] -> ShowS #

data Value Source #

Constructors

VT !Text 
VI !Scientific 
VB !Bool 
VLT !LocalTime 
VD !Day 
VH !TimeOfDay 
VU !UTCTime 
VR ![VRef] 
Instances
Eq Value Source # 
Instance details

Defined in Salak.Internal.Val

Methods

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

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

Show Value Source # 
Instance details

Defined in Salak.Internal.Val

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

ToValue Value Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: Value -> Value Source #

data VRef Source #

Constructors

VRT !Text 
VRR !Keys ![VRef] 
Instances
Eq VRef Source # 
Instance details

Defined in Salak.Internal.Val

Methods

(==) :: VRef -> VRef -> Bool #

(/=) :: VRef -> VRef -> Bool #

Show VRef Source # 
Instance details

Defined in Salak.Internal.Val

Methods

showsPrec :: Int -> VRef -> ShowS #

show :: VRef -> String #

showList :: [VRef] -> ShowS #

class ToValue a where Source #

Methods

toVal :: a -> Value Source #

Instances
ToValue Bool Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: Bool -> Value Source #

ToValue Double Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: Double -> Value Source #

ToValue Int Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: Int -> Value Source #

ToValue Int64 Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: Int64 -> Value Source #

ToValue Integer Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: Integer -> Value Source #

ToValue String Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: String -> Value Source #

ToValue ByteString Source # 
Instance details

Defined in Salak.Internal.Val

ToValue Text Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: Text -> Value Source #

ToValue Scientific Source # 
Instance details

Defined in Salak.Internal.Val

ToValue UTCTime Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: UTCTime -> Value Source #

ToValue Value Source # 
Instance details

Defined in Salak.Internal.Val

Methods

toVal :: Value -> Value Source #

data SourcePack Source #

Constructors

SourcePack 

Fields

class Monad m => MonadIO (m :: Type -> Type) #

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Minimal complete definition

liftIO

Instances
MonadIO IO

Since: base-4.9.0.0

Instance details

Defined in Control.Monad.IO.Class

Methods

liftIO :: IO a -> IO a #

MonadIO Q 
Instance details

Defined in Language.Haskell.TH.Syntax

Methods

liftIO :: IO a -> Q a #

MonadIO m => MonadIO (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

liftIO :: IO a -> MaybeT m a #

MonadIO m => MonadIO (ListT m) 
Instance details

Defined in Control.Monad.Trans.List

Methods

liftIO :: IO a -> ListT m a #

MonadIO m => MonadIO (Prop m) Source # 
Instance details

Defined in Salak.Internal.Prop

Methods

liftIO :: IO a -> Prop m a #

MonadIO m => MonadIO (RunSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

liftIO :: IO a -> RunSalakT m a #

MonadIO m => MonadIO (LoadSalakT m) Source # 
Instance details

Defined in Salak.Internal

Methods

liftIO :: IO a -> LoadSalakT m a #

MonadIO m => MonadIO (ExceptT e m) 
Instance details

Defined in Control.Monad.Trans.Except

Methods

liftIO :: IO a -> ExceptT e m a #

MonadIO m => MonadIO (IdentityT m) 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

liftIO :: IO a -> IdentityT m a #

(Error e, MonadIO m) => MonadIO (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

liftIO :: IO a -> ErrorT e m a #

MonadIO m => MonadIO (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

liftIO :: IO a -> StateT s m a #

MonadIO m => MonadIO (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

liftIO :: IO a -> StateT s m a #

(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

liftIO :: IO a -> WriterT w m a #

(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

liftIO :: IO a -> WriterT w m a #

(Stream s, MonadIO m) => MonadIO (ParsecT e s m) 
Instance details

Defined in Text.Megaparsec.Internal

Methods

liftIO :: IO a -> ParsecT e s m a #

MonadIO m => MonadIO (ContT r m) 
Instance details

Defined in Control.Monad.Trans.Cont

Methods

liftIO :: IO a -> ContT r m a #

MonadIO m => MonadIO (ReaderT r m) 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

liftIO :: IO a -> ReaderT r m a #

(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

liftIO :: IO a -> RWST r w s m a #

(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

liftIO :: IO a -> RWST r w s m a #

runProp :: MonadThrow m => SourcePack -> Prop m a -> m a Source #

withKeys :: Keys -> Prop m a -> Prop m a Source #

genSource :: (Foldable f, ToKeys k, ToValue v) => Int -> f (k, v) -> TraceSource Source #

Writable Value

data Writable a Source #

Writable data structure. Writable is designed for working with IO value pased by salak. It provide a way to override IO value provided by salak, can be used in the application which need to change values of some configurations by overriding it directly. For example, logger function can use a log level property to control which level of logs should be printed. By using Writeable value, we can change the property directly.

toWritable :: IO a -> IO (Writable a) Source #

Convert a IO value to Writable value.

getWritable :: Writable a -> IO a Source #

Get value.

setWritable :: Maybe a -> Writable a -> IO () Source #

Set or remove override value.