specify v0.10.0 Specify View Source
Specify allows you to make your configuration explicit:
- Specify exactly what fields are expected.
- Specify exactly what values these fields might take, by giving them parser-functions.
- Load their values from a slew of different locations, with 'explicitly passed in to the function' as final option.
Link to this section Summary
Functions
Defines a configuration structure in the current module.
Loads, parses, and normalizes the configuration of config_module
, based on the current source settings, returning the result as a struct.
Loads, parses and normalizes the configuration of config_module
, using the provided explicit_values
(and falling back to values configured elsewhere)
Link to this section Functions
Defines a configuration structure in the current module.
Fields are added to this configuration structure by calling Specify.Schema.field/3
(which can be called just as field
because Specify.Schema
is autoamatically imported into the
inner context of the call to defconfig
.)
The options
that can be passed to this module are used as defaults for the options passed to a call to Specify.load/2
or YourModule.load/1
.
See also Specify.Schema.field/3
and Specify.Options
Reflection
The special function __specify__/1
will be defined on the module as well. It is not intended to be used
by people that want to consume your configuration,
but it is there to e.g. allow Specify.Provider
implementations to be smarter
in how they fetch the configuration for the module. For instance, configuration
might be lazily fetched, when knowing what field names exist beforehand.
YourModule.__specify__/1
supports the following publicly usable parameters:
__specify__(:field_names)
returns a MapSet of atoms, one per field in the configuration structure.__specify__(:defaults)
returns a Map containing only thefield_name => value
s of field names having default values.__specify__(:requireds)
returns a MapSet of atoms, one per required field in the configuration structure.__specify__(:parsers)
returns a Map of the formatfield_name => parser
.__specify__(:field_options)
returns a Map of the formatfield_name => options
, whereoptions
is the keyword-list that was passed to thefield
macro.
Loads, parses, and normalizes the configuration of config_module
, based on the current source settings, returning the result as a struct.
(This is the more general way of calling config_module.load/1
).
See Specify.Options
for more information of the options that can be supplied to this function,
and how it can be configured further.
Loads, parses and normalizes the configuration of config_module
, using the provided explicit_values
(and falling back to values configured elsewhere)
This call is conceptually the same as Specify.load(config_module, [explicit_values: [] | options])
, but makes it more explicit that values
are meant to be passed in as arguments.
Prefer this function if you do not intend to use Specify's 'cascading configuration' functionality, such as when e.g. just parsing options passed to a function,
use
-statement or other macro.