Simplified helpers to work with Application configs in Elixir.
Before using this module, you must add the following to your
config.exs file:
config :ex_utils, otp_app: :your_appReplace :your_app with the actual OTP app atom.
Summary
Functions
Build the absolute path of a file in the priv/ directory,
given its relative path.
Gets a config value for the given access path.
Reads the application configs of the OTP app.
Same as get/3 but raises when the value is nil or not found and no
default is provided.
Read a file stored in the priv/ directory.
Functions
Build the absolute path of a file in the priv/ directory,
given its relative path.
This is especially useful in compiled elixir releases.
Examples
During development, the returned path might look like:
iex> ExUtils.Configs.from_priv!("templates/email.html")
"priv/templates/email.html"In a compiled release, it might look like:
iex> ExUtils.Configs.from_priv!("templates/email.html")
"/opt/my_app/lib/my_app-1.0.0/priv/templates/email.html"
Gets a config value for the given access path.
Returns the given default when the value is nil or does not exist.
Examples
Given config :your_app, :features, uploads: [enabled: true]:
iex> ExUtils.Configs.get(:features, [:uploads, :enabled])
true
iex> ExUtils.Configs.get(:features, [:uploads, :max_size], :unlimited)
:unlimited
Reads the application configs of the OTP app.
Raises if the value is nil or does not exist.
Example
Given the following application config:
config :your_app, :mailer, adapter: MyApp.LocalAdapterIt can be retrieved with:
iex> ExUtils.Configs.get!(:mailer)
[adapter: MyApp.LocalAdapter]
Same as get/3 but raises when the value is nil or not found and no
default is provided.
Read a file stored in the priv/ directory.
Accepts a relative path of file inside priv.
Example
Given a priv/messages/welcome.txt file containing Welcome!:
iex> ExUtils.Configs.read_from_priv!("messages/welcome.txt")
"Welcome!"