ConfigExt 
A bunch of common elixir config helpers to load config from environment variables or by executing a function. Part of the work was based on gist from bitwalker and community practises (especially for using {:system, "VAR"[, default]}
spec).
Installation
The package can be installed as:
Add
config_ext
to your list of dependencies inmix.exs
:def deps do [{:config_ext, "~> 0.1.0"}] end
Usage
You can use the module to load info from system environment variables like
# where LEVEL=debug
iex>
ConfigExt.load({:system, "LEVEL")
{:ok, "debug"}
or add default value as well
# when LEVEL is empty
iex> ConfigExt.load({:system, "LEVEL", "info"})
{:ok, "info"}
# or in different format
iex> ConfigExt.load({:system, "LEVEL"}, "info")
{:ok, "info"}
or execute a function instead
defmodule Foo do
def bar(a), do: "baz-#{inspect(a)}"
end
iex> ConfigExt.load({:function, Foo, :bar, [:a]})
{:ok, "baz-:a"}
Of course it’s meant to be run as part of other libaries, in order to load config dynamically, at the moment you can do it like:
# i.e. in config.exs
config :logger, level: {:system, "LEVEL", "info"}
# then LEVEL=warn
iex> Application.get_env(:logger, :level) |> ConfigExt.load("error")
{:ok, "warn"}
See more in docs ConfigExt.load/1
and ConfigExt.load/2
.