| Copyright | (c) 2019 Lucas David Traverso |
|---|---|
| License | MPL-2.0 |
| Maintainer | Lucas David Traverso <lucas6246@gmail.com> |
| Stability | unstable |
| Portability | portable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Conferer.FromConfig.Internal
Description
Internal module providing FromConfig functionality
Synopsis
- class FromConfig a where
- fetchFromConfig :: Key -> Config -> IO a
- class DefaultConfig a where
- configDef :: a
- newtype File = File FilePath
- parseBool :: Text -> Maybe Bool
- fetchFromConfigByRead :: (Typeable a, Read a) => Key -> Config -> IO a
- fetchFromConfigByIsString :: (Typeable a, IsString a) => Key -> Config -> IO a
- fetchFromConfigWith :: forall a. Typeable a => (Text -> Maybe a) -> Key -> Config -> IO a
- addDefaultsAfterDeconstructingToDefaults :: forall a. Typeable a => (a -> [(Key, Dynamic)]) -> Key -> Config -> IO Config
- data ConfigParsingError = ConfigParsingError Key Text TypeRep
- throwConfigParsingError :: forall a b. Typeable a => Key -> Text -> IO b
- configParsingError :: forall a. Typeable a => Key -> Text -> ConfigParsingError
- data MissingRequiredKey = MissingRequiredKey [Key] TypeRep
- throwMissingRequiredKey :: forall t a. Typeable t => Key -> IO a
- missingRequiredKey :: forall t. Typeable t => Key -> MissingRequiredKey
- throwMissingRequiredKeys :: forall t a. Typeable t => [Key] -> IO a
- missingRequiredKeys :: forall a. Typeable a => [Key] -> MissingRequiredKey
- data TypeMismatchWithDefault = TypeMismatchWithDefault Key Dynamic TypeRep
- throwTypeMismatchWithDefault :: forall a b. Typeable a => Key -> Dynamic -> IO b
- typeMismatchWithDefault :: forall a. Typeable a => Key -> Dynamic -> TypeMismatchWithDefault
- fetchRequiredFromDefaults :: forall a. Typeable a => Key -> Config -> IO a
- fetchFromDefaults :: forall a. Typeable a => Key -> Config -> IO (Maybe a)
- fetchFromRootConfig :: forall a. FromConfig a => Config -> IO a
- fetchFromConfigWithDefault :: forall a. (Typeable a, FromConfig a) => Config -> Key -> a -> IO a
- fetchFromRootConfigWithDefault :: forall a. (Typeable a, FromConfig a) => Config -> a -> IO a
- class FromConfigG f where
- fetchFromConfigG :: Key -> Config -> IO (f a)
- class FromConfigWithConNameG f where
- fetchFromConfigWithConNameG :: String -> Key -> Config -> IO (f a)
- class IntoDefaultsG f where
- intoDefaultsG :: Key -> f a -> [(Key, Dynamic)]
- class IntoDefaultsWithConNameG f where
- intoDefaultsWithConNameG :: String -> Key -> f a -> [(Key, Dynamic)]
Documentation
class FromConfig a where Source #
The typeclass for defining the way to get values from a Config, hiding the
Text based nature of the Sources and parse whatever value
as the types sees fit
Some of these instances are provided in different packages to avoid the heavy dependencies.
It provides a reasonable default using Generics so most of the time user need
not to implement this typeclass.
Minimal complete definition
Nothing
Methods
fetchFromConfig :: Key -> Config -> IO a Source #
This function uses a Config and a scoping Key to get a value.
Some conventions:
- When some
Keyis missing this function should throwMissingRequiredKey - For any t it should hold that
fetchFromConfig k (config & addDefault k t) == tmeaning that a default on the same key with the right type should be used as a default and with no configuration that value should be returned - Try desconstructing the value in as many keys as possible since is allows easier partial overriding.
default fetchFromConfig :: (Typeable a, Generic a, IntoDefaultsG (Rep a), FromConfigG (Rep a)) => Key -> Config -> IO a Source #
Instances
class DefaultConfig a where Source #
Utility only typeclass to smooth the naming differences between default values for external library settings
This typeclass is not used internally it's only here for convinience for users
A newtype wrapper for a FilePath to allow implementing FromConfig
with something better than just a String
fetchFromConfigByRead :: (Typeable a, Read a) => Key -> Config -> IO a Source #
Helper function to implement fetchFromConfig using the Read instance
fetchFromConfigByIsString :: (Typeable a, IsString a) => Key -> Config -> IO a Source #
Helper function to implement fetchFromConfig using the IsString instance
fetchFromConfigWith :: forall a. Typeable a => (Text -> Maybe a) -> Key -> Config -> IO a Source #
Helper function to implement fetchFromConfig using some parsing function
addDefaultsAfterDeconstructingToDefaults Source #
Arguments
| :: forall a. Typeable a | |
| => (a -> [(Key, Dynamic)]) | Function to deconstruct the value |
| -> Key | Key where to look for the value |
| -> Config | The config |
| -> IO Config |
Helper function does the plumbing of desconstructing a default into smaller
defaults, which is usefull for nested fetchFromConfig.
data ConfigParsingError Source #
Exception to show that a value couldn't be parsed properly
Constructors
| ConfigParsingError Key Text TypeRep |
Instances
| Eq ConfigParsingError Source # | |
Defined in Conferer.FromConfig.Internal Methods (==) :: ConfigParsingError -> ConfigParsingError -> Bool # (/=) :: ConfigParsingError -> ConfigParsingError -> Bool # | |
| Show ConfigParsingError Source # | |
Defined in Conferer.FromConfig.Internal Methods showsPrec :: Int -> ConfigParsingError -> ShowS # show :: ConfigParsingError -> String # showList :: [ConfigParsingError] -> ShowS # | |
| Exception ConfigParsingError Source # | |
Defined in Conferer.FromConfig.Internal Methods toException :: ConfigParsingError -> SomeException # fromException :: SomeException -> Maybe ConfigParsingError # | |
throwConfigParsingError :: forall a b. Typeable a => Key -> Text -> IO b Source #
Helper function to throw ConfigParsingError
configParsingError :: forall a. Typeable a => Key -> Text -> ConfigParsingError Source #
Helper function to create a ConfigParsingError
data MissingRequiredKey Source #
Exception to show that some non optional Key was missing while trying
to fetchFromConfig
Constructors
| MissingRequiredKey [Key] TypeRep |
Instances
| Eq MissingRequiredKey Source # | |
Defined in Conferer.FromConfig.Internal Methods (==) :: MissingRequiredKey -> MissingRequiredKey -> Bool # (/=) :: MissingRequiredKey -> MissingRequiredKey -> Bool # | |
| Show MissingRequiredKey Source # | |
Defined in Conferer.FromConfig.Internal Methods showsPrec :: Int -> MissingRequiredKey -> ShowS # show :: MissingRequiredKey -> String # showList :: [MissingRequiredKey] -> ShowS # | |
| Exception MissingRequiredKey Source # | |
Defined in Conferer.FromConfig.Internal Methods toException :: MissingRequiredKey -> SomeException # fromException :: SomeException -> Maybe MissingRequiredKey # | |
throwMissingRequiredKey :: forall t a. Typeable t => Key -> IO a Source #
Simplified helper function to throw a MissingRequiredKey
missingRequiredKey :: forall t. Typeable t => Key -> MissingRequiredKey Source #
Simplified helper function to create a MissingRequiredKey
throwMissingRequiredKeys :: forall t a. Typeable t => [Key] -> IO a Source #
Helper function to throw a MissingRequiredKey
missingRequiredKeys :: forall a. Typeable a => [Key] -> MissingRequiredKey Source #
Helper function to create a MissingRequiredKey
data TypeMismatchWithDefault Source #
Exception to show that the provided default had the wrong type, this is usually a programmer error and a user that configures the library can not do much to fix it.
Constructors
| TypeMismatchWithDefault Key Dynamic TypeRep |
Instances
| Eq TypeMismatchWithDefault Source # | |
Defined in Conferer.FromConfig.Internal Methods (==) :: TypeMismatchWithDefault -> TypeMismatchWithDefault -> Bool # (/=) :: TypeMismatchWithDefault -> TypeMismatchWithDefault -> Bool # | |
| Show TypeMismatchWithDefault Source # | |
Defined in Conferer.FromConfig.Internal Methods showsPrec :: Int -> TypeMismatchWithDefault -> ShowS # show :: TypeMismatchWithDefault -> String # showList :: [TypeMismatchWithDefault] -> ShowS # | |
| Exception TypeMismatchWithDefault Source # | |
Defined in Conferer.FromConfig.Internal | |
throwTypeMismatchWithDefault :: forall a b. Typeable a => Key -> Dynamic -> IO b Source #
Helper function to throw a TypeMismatchWithDefault
typeMismatchWithDefault :: forall a. Typeable a => Key -> Dynamic -> TypeMismatchWithDefault Source #
Helper function to create a TypeMismatchWithDefault
fetchRequiredFromDefaults :: forall a. Typeable a => Key -> Config -> IO a Source #
Fetch from value from the defaults map of a Config or else throw
fetchFromRootConfig :: forall a. FromConfig a => Config -> IO a Source #
Same as fetchFromConfig using the root key
fetchFromConfigWithDefault :: forall a. (Typeable a, FromConfig a) => Config -> Key -> a -> IO a Source #
Same as fetchFromConfig but adding a user defined default before fetchFromConfiging
so it doesn't throw a MissingKeyError
fetchFromRootConfigWithDefault :: forall a. (Typeable a, FromConfig a) => Config -> a -> IO a Source #
Same as fetchFromConfigWithDefault using the root key
class FromConfigG f where Source #
Purely Generics machinery, ignore...
Instances
| FromConfig inner => FromConfigG (Rec0 inner) Source # | |
Defined in Conferer.FromConfig.Internal | |
| FromConfigG inner => FromConfigG (D1 metadata inner) Source # | |
Defined in Conferer.FromConfig.Internal | |
| (FromConfigWithConNameG inner, Constructor constructor) => FromConfigG (C1 constructor inner) Source # | |
Defined in Conferer.FromConfig.Internal | |
class FromConfigWithConNameG f where Source #
Purely Generics machinery, ignore...
Instances
| (FromConfigWithConNameG left, FromConfigWithConNameG right) => FromConfigWithConNameG (left :*: right) Source # | |
Defined in Conferer.FromConfig.Internal | |
| (FromConfigG inner, Selector selector) => FromConfigWithConNameG (S1 selector inner) Source # | |
Defined in Conferer.FromConfig.Internal | |
class IntoDefaultsG f where Source #
Purely Generics machinery, ignore...
Instances
| Typeable inner => IntoDefaultsG (Rec0 inner) Source # | |
Defined in Conferer.FromConfig.Internal | |
| IntoDefaultsG inner => IntoDefaultsG (D1 metadata inner) Source # | |
Defined in Conferer.FromConfig.Internal | |
| (IntoDefaultsWithConNameG inner, Constructor constructor) => IntoDefaultsG (C1 constructor inner) Source # | |
Defined in Conferer.FromConfig.Internal | |
class IntoDefaultsWithConNameG f where Source #
Purely Generics machinery, ignore...
Instances
| (IntoDefaultsWithConNameG left, IntoDefaultsWithConNameG right) => IntoDefaultsWithConNameG (left :*: right) Source # | |
Defined in Conferer.FromConfig.Internal | |
| (IntoDefaultsG inner, Selector selector) => IntoDefaultsWithConNameG (S1 selector inner) Source # | |
Defined in Conferer.FromConfig.Internal | |