Copyright | 2019 Daniel YU |
---|---|
License | MIT |
Maintainer | leptonyu@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
This module is used for implementing loaders.
Synopsis
- loadAndRunSalak' :: (MonadThrow m, MonadIO m) => LoadSalakT m () -> (SourcePack -> m a) -> m a
- loadAndRunSalak :: (MonadThrow m, MonadIO m) => LoadSalakT m () -> RunSalakT m a -> m a
- loadTrie :: (MonadThrow m, MonadIO m) => Bool -> String -> (Int -> IO TraceSource) -> LoadSalakT m ()
- loadList :: (MonadThrow m, MonadIO m, Foldable f, ToKeys k, ToValue v) => Bool -> String -> IO (f (k, v)) -> LoadSalakT m ()
- data LoadSalakT m a
- type LoadSalak = LoadSalakT IO
- data RunSalakT m a
- type RunSalak = RunSalakT IO
- class Monad m => MonadSalak m where
- askSourcePack :: m SourcePack
- askReload :: m (IO ReloadResult)
- setLogF :: MonadIO m => (CallStack -> Text -> IO ()) -> m ()
- logSalak :: (HasCallStack, MonadIO m) => Text -> m ()
- require :: (MonadThrow m, MonadIO m, FromProp m a) => Text -> m a
- loadMock :: (MonadThrow m, MonadIO m) => [(Text, Text)] -> LoadSalakT m ()
- loadEnv :: (MonadThrow m, MonadIO m) => LoadSalakT m ()
- loadCommandLine :: (MonadThrow m, MonadIO m) => ParseCommandLine -> LoadSalakT m ()
- type ParseCommandLine = [String] -> IO [(Text, Text)]
- defaultParseCommandLine :: ParseCommandLine
- tryLoadFile :: MonadIO m => (FilePath -> LoadSalakT m ()) -> FilePath -> LoadSalakT m ()
- type Source = Trie Vals
- type TraceSource = Trie TraceVals
- newtype Keys = Keys {}
- data Key
- simpleKeys :: Text -> Keys
- fromKeys :: [Key] -> Keys
- class ToKeys a where
- setVal :: ToValue v => Int -> v -> TraceSource -> TraceSource
- data Val v = Val !Int !v
- data Value
- data VRef
- mkValue :: Value -> Either String Value
- class ToValue a where
- liftNT :: MonadIO m => LoadSalak () -> LoadSalakT m ()
- data SourcePack = SourcePack {}
- runProp :: MonadThrow m => SourcePack -> Prop m a -> m a
- withKeys :: Keys -> Prop m a -> Prop m a
- extract :: Source -> TraceSource -> (Source, Trie ModType, [String])
- genSource :: (Foldable f, ToKeys k, ToValue v) => Int -> f (k, v) -> TraceSource
- data Writable a
- toWritable :: IO a -> IO (Writable a)
- getWritable :: Writable a -> IO a
- setWritable :: Maybe a -> Writable a -> IO ()
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
type LoadSalak = LoadSalakT IO Source #
Simple IO Monad
Standard MonadSalak
instance.
Instances
class Monad m => MonadSalak m where Source #
Core type class of salak, which provide function to parse properties.
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.
Instances
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
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 TraceSource = Trie TraceVals Source #
simpleKeys :: Text -> Keys Source #
setVal :: ToValue v => Int -> v -> TraceSource -> TraceSource Source #
class ToValue a where Source #
Instances
ToValue Bool Source # | |
ToValue Double Source # | |
ToValue Int Source # | |
ToValue Int64 Source # | |
ToValue Integer Source # | |
ToValue String Source # | |
ToValue ByteString Source # | |
Defined in Salak.Internal.Val toVal :: ByteString -> Value Source # | |
ToValue Text Source # | |
ToValue Scientific Source # | |
Defined in Salak.Internal.Val toVal :: Scientific -> Value Source # | |
ToValue UTCTime Source # | |
ToValue Value Source # | |
data SourcePack Source #
Instances
Monad m => MonadReader SourcePack (Prop m) Source # | |
Defined in Salak.Internal.Prop ask :: Prop m SourcePack # local :: (SourcePack -> SourcePack) -> Prop m a -> Prop m a # reader :: (SourcePack -> a) -> Prop m a # | |
Monad m => MonadReader SourcePack (RunSalakT m) Source # | |
Defined in Salak.Internal ask :: RunSalakT m SourcePack # local :: (SourcePack -> SourcePack) -> RunSalakT m a -> RunSalakT m a # reader :: (SourcePack -> a) -> RunSalakT m a # | |
Monad m => MonadSalak (ReaderT SourcePack m) Source # | |
Defined in Salak.Internal.Prop askSourcePack :: ReaderT SourcePack m SourcePack Source # askReload :: ReaderT SourcePack m (IO ReloadResult) Source # setLogF :: (CallStack -> Text -> IO ()) -> ReaderT SourcePack m () Source # logSalak :: Text -> ReaderT SourcePack m () Source # require :: (MonadThrow (ReaderT SourcePack m), MonadIO (ReaderT SourcePack m), FromProp (ReaderT SourcePack m) a) => Text -> ReaderT SourcePack m a Source # |
runProp :: MonadThrow m => SourcePack -> Prop m a -> m a Source #
Writable Value
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.
getWritable :: Writable a -> IO a Source #
Get value.