View Source Config.Reader (Elixir v1.10.3)
API for reading config files defined with Config
.
As a provider
Config.Reader
can also be used as a Config.Provider
. When used
as a provider, it expects a single argument: the configuration path
(as outlined in Config.Provider.config_path/0
) for the file to
be read and loaded during the system boot.
For example, if you expect the target system to have a config file
in an absolute path, you can configure your mix release
as:
config_providers: [{Config.Reader, "/etc/config.exs"}]
Or if you want to read a custom path inside the release:
config_provider: [{Config.Reader, {:system, "RELEASE_ROOT", "/config.exs"}}]
Note by default Mix releases supports runtime configuration via
a config/releases.exs
. If a config/releases.exs
exists in your
application, it is automatically copied inside the release and
automatically set as a config provider.
Link to this section Summary
Functions
Merges two configurations.
Reads the configuration file.
Reads the given configuration file alongside its imports.
Link to this section Functions
Merges two configurations.
The configurations are merged together with the values in the second one having higher preference than the first in case of conflicts. In case both values are set to keyword lists, it deep merges them.
Examples
iex> Config.Reader.merge([app: [k: :v1]], [app: [k: :v2]])
[app: [k: :v2]]
iex> Config.Reader.merge([app: [k: [v1: 1, v2: 2]]], [app: [k: [v2: :a, v3: :b]]])
[app: [k: [v1: 1, v2: :a, v3: :b]]]
iex> Config.Reader.merge([app1: []], [app2: []])
[app1: [], app2: []]
Reads the configuration file.
The same as read_imports!/2
but only returns the configuration
in the given file, without returning the imported paths.
It exists for convenience purposes. For example, you could
invoke it inside your mix.exs
to read some external data
you decided to move to a configuration file:
releases: Config.Reader.read!("rel/releases.exs")
Reads the given configuration file alongside its imports.
It accepts a list of imported_paths
that should raise if attempted
to be imported again (to avoid recursive imports).
It returns a tuple with the configuration and the imported paths.