env_helper v0.0.5 EnvHelper
Helpers for enviroment and application variables.
Summary
Macros
defines a method name/0
which returns either the application variable for appname[key]
or the provided alt
value
creates a method name/0
which returns either alt
or the environment variable set for the upcase version name
creates a method name/0
which returns either alt
or the environment variable set for the upcase version name
, cast to an integer
Macros
defines a method name/0
which returns either the application variable for appname[key]
or the provided alt
value.
Works best in simple cases, such as config :appname, :key, value
Example (simple app variable)
defmodule AppEnvs do
import EnvHelper
app_env(:port, [:appname, :port], 1234)
end
> AppEnvs.port
1234
> Application.put_env(:appname, :port, 5678)
:ok
> AppEnvs.port
5678
Example (nested app variable)
defmodule AppEnvs do
import EnvHelper
defmodule Section do
app_env(:secret, [:appname, :section, :secret], "default secret")
end
end
> AppEnvs.Section.secret
"default secret"
> Application.puts_env(:appname, :section, [secret: "my super secret"])
:ok
> AppEnvs.Section.secret
"my super secret"
creates a method name/0
which returns either alt
or the environment variable set for the upcase version name
.
Paramenters
name
:: atomThe name of a system environment variable, downcase, as an atom
alt
:: anyThe value used if the system variable is not set.
Example
defmodule EnvSets do
import EnvHelper
system_env(:app_url, "localhost:2000")
end
> EnvSets.app_url
"localhost:2000"
> System.put_env("APP_URL", "app.io")
:ok
> EnvSets.app_url
"app.io"
creates a method name/0
which returns either alt
or the environment variable set for the upcase version name
, cast to an integer.
Paramenters
name
:: atomThe name of a system environment variable, downcase, as an atom
alt
:: anyThe value used if the system variable is not set.
:string_to_integer
forces the returned value to be an integer.
Example
defmodule EnvSets do
import EnvHelper
system_env(:app_port, 2000, :string_to_integer)
end
> EnvSets.app_port
2000
> System.put_env("APP_PORT", "2340")
:ok
> EnvSets.app_port
2340
> System.put_env("APP_PORT", 2360)
:ok
> EnvSets.app_url
2360