Application.compile_env
You're seeing just the macro
compile_env
, go back to Application module for more information.
Specs
Reads the application environment at compilation time.
Similar to get_env/3
, except it must be used to read values
at compile time. This allows Elixir to track when configuration
values change between compile time and runtime.
The first argument is the application name. The second argument
key_or_path
is either an atom key or a path to traverse in
search of the configuration, starting with an atom key.
For example, imagine the following configuration:
config :my_app, :key, [foo: [bar: :baz]]
We can access it during compile time as:
Application.compile_env(:my_app, :key)
#=> [foo: [bar: :baz]]
Application.compile_env(:my_app, [:key, :foo])
#=> [bar: :baz]
Application.compile_env(:my_app, [:key, :foo, :bar])
#=> :baz
A default value can also be given as third argument. If any of the keys in the path along the way is missing, the default value is used:
Application.compile_env(:my_app, [:unknown, :foo, :bar], :default)
#=> :default
Application.compile_env(:my_app, [:key, :unknown, :bar], :default)
#=> :default
Application.compile_env(:my_app, [:key, :foo, :unknown], :default)
#=> :default
Giving a path is useful to let Elixir know that only certain paths in a large configuration are compile time dependent.