atmo v0.1.0 Atmo
A single, flexible interface for reading configuration from environment
variables or Mix.Config
with parsing and defaults. This is most useful
for development of applications where config files are useful in testing
and development but must be overridden by environment variables in
production.
Atmo will convert any atom passed to a string and
- Environment variable of the same name
- Environment variable matching the name in all-caps
- Environment variable matching the name in all-lowercase
- Elixir configuration from any application matching the name as an atom
- Elixir configuration from any application matching the name as an atom in all-lowercase
- Elixir configuration from any application matching the name as an atom in all-caps
Examples
iex> System.put_env("ATMO_TEST_ENV_VAR", "foo")
...> Atmo.get("ATMO_TEST_ENV_VAR")
"foo"
iex> System.put_env("ATMO_TEST_ENV_VAR", "foo")
...> Atmo.get(:atmo_test_env_var)
"foo"
iex> Application.put_env(:atmo, :config_var, "bar") # Any loaded application's config.exs
...> Atmo.clear_cache
...> Atmo.get(:config_var)
"bar"
Summary
Functions
Clears the config cache. This is useful in the event that environment changes are made while the application is runnig or during testing
Returns the value of the config by name. If the configuration is not found
in either environment variables or the application config, the default
value is returned
Returns the value of the configuration parsed as a float. If the value
cannot be parsed, nil
is returned
Returns the value of the configuration parsed as an integer. If the value
cannot be parsed, nil
is returned
Returns the value of the configuration as a String
Functions
Specs
clear_cache :: atom
Clears the config cache. This is useful in the event that environment changes are made while the application is runnig or during testing.
Examples
iex> System.put_env("ATMO_TEST_ENV_VAR", "foo")
...> Atmo.get("ATMO_TEST_ENV_VAR")
"foo"
iex> System.put_env("ATMO_TEST_ENV_VAR", "bar")
...> Atmo.get("ATMO_TEST_ENV_VAR")
"foo"
iex> Atmo.clear_cache
...> Atmo.get("ATMO_TEST_ENV_VAR") # => "foo"
"bar"
Specs
get(binary | atom, binary) :: binary
Returns the value of the config by name. If the configuration is not found
in either environment variables or the application config, the default
value is returned.
Equivalent to get_string/2
Specs
get_float(binary | atom, float) :: float
Returns the value of the configuration parsed as a float. If the value
cannot be parsed, nil
is returned.
Examples
iex> System.put_env("ATMO_TEST_FLOAT", "42.123")
...> Atmo.get_float("ATMO_TEST_FLOAT")
42.123
iex> Atmo.get_float("MISSING_VARIABLE", 37.321)
37.321
Specs
get_integer(binary | atom, integer) :: integer
Returns the value of the configuration parsed as an integer. If the value
cannot be parsed, nil
is returned.
Examples
iex> System.put_env("ATMO_TEST_INT", "42")
...> Atmo.get_integer("ATMO_TEST_INT")
42
iex> Atmo.get_integer("MISSING_VARIABLE")
nil
iex> Atmo.get_integer("MISSING_VARIABLE", 37)
37