View Source Config.Reader (Elixir v1.12.0)
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_providers: [{Config.Reader, {:system, "RELEASE_ROOT", "/config.exs"}}]
You can also pass a keyword list of options to the reader,
where the :path
is a required key:
config_providers: [
{Config.Reader,
path: "/etc/config.exs",
env: :prod,
imports: :disabled}
]
Note by default Mix releases supports runtime configuration via
a config/runtime.exs
. If a config/runtime.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
Evaluates the configuration contents
for the given file
.
Merges two configurations.
Reads the configuration file.
Reads the given configuration file and returns the configuration with its imports.
Link to this section Functions
Evaluates the configuration contents
for the given file
.
Accepts the same options as read!/2
.
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.
Options
:imports
- a list of already imported paths or:disabled
to disable imports:env
- the environment the configuration file runs on. SeeConfig.config_env/0
for sample usage:target
- the target the configuration file runs on. SeeConfig.config_target/0
for sample usage
Reads the given configuration file and returns the configuration with its imports.
Accepts the same options as read!/2
. Although note the :imports
option cannot be disabled in read_imports!/2
.