@@ -4,8 +4,8 @@ defmodule Config do
4
4
5
5
## Example
6
6
7
- This module is most commonly used to define application
8
- configuration, typically in `config/config.exs`:
7
+ This module is most commonly used to define application configuration,
8
+ typically in `config/config.exs`:
9
9
10
10
import Config
11
11
@@ -18,14 +18,20 @@ defmodule Config do
18
18
`import Config` will import the functions `config/2`, `config/3`
19
19
and `import_config/1` to help you manage your configuration.
20
20
21
- Once Mix starts, it will automatically evaluate the configuration
22
- file and persist it into `:some_app`'s application environment, which
23
- can be accessed in as follows:
21
+ `config/2` and `config/3` are used to define key-value configuration
22
+ for a given application. Once Mix starts, it will automatically
23
+ evaluate the configuration file and persist the configuration above
24
+ into `:some_app`'s application environment, which can be accessed in
25
+ as follows:
24
26
25
27
"value1" = Application.fetch_env!(:some_app, :key1)
26
28
27
- See `Config.Reader` for evaluating and reading configuration
28
- files.
29
+ Finally, the line `import_config "#{Mix.env()}.exs"` will import other
30
+ config files, based on the current Mix environment, such as
31
+ `config/dev.exs` and `config/test.exs`.
32
+
33
+ `Config` also provides a low-level API for evaluating and reading
34
+ configuration, under the `Config.Reader` module.
29
35
30
36
**Important:** if you are writing a library to be used by other developers,
31
37
it is generally recommended to avoid the application environment, as the
@@ -34,17 +40,16 @@ defmodule Config do
34
40
35
41
## Migrating from `use Mix.Config`
36
42
37
- The `Config` module in Elixir was introduced in v1.9 as a
38
- replacement to `Mix.Config`, which was specific to Mix and
39
- has been deprecated.
43
+ The `Config` module in Elixir was introduced in v1.9 as a replacement to
44
+ `Mix.Config`, which was specific to Mix and has been deprecated.
40
45
41
- You can leverage `Config` instead of `Mix.Config` in two steps.
42
- The first step is to replace `use Mix.Config` at the top of
43
- your config files by `import Config`.
46
+ You can leverage `Config` instead of `Mix.Config` in two steps. The first
47
+ step is to replace `use Mix.Config` at the top of your config files by
48
+ `import Config`.
44
49
45
- The second is to make sure your `import_config/1` calls do
46
- not have a wildcard character. If so, you need to perform
47
- the wildcard lookup manually. For example, if you did:
50
+ The second is to make sure your `import_config/1` calls do not have a
51
+ wildcard character. If so, you need to perform the wildcard lookup
52
+ manually. For example, if you did:
48
53
49
54
import_config "../apps/*/config/config.exs"
50
55
@@ -54,6 +59,15 @@ defmodule Config do
54
59
import_config config
55
60
end
56
61
62
+ ## config/releases.exs
63
+
64
+ If you are using releases, see `mix release`, there another configuration
65
+ file called `config/releases.exs`. While `config/config.exs` and friends
66
+ mentioned in the previous section are executed whenever you run a Mix
67
+ command, including when you assemble a release, `config/releases.exs` is
68
+ execute every time your production system boots. Since Mix is not available
69
+ in a production system, `config/releases.exs` must not use any of the
70
+ functions from Mix.
57
71
"""
58
72
59
73
@ config_key { __MODULE__ , :config }
0 commit comments