Skogsrå v2.2.3 Skogsra View Source
This module defines the macros needed to use Skogsra
e.g:
defmodule MyApp.Settings do
use Skogsra
@envdoc "My hostname"
app_env :my_hostname, :myapp, :hostname,
default: "localhost"
end
Link to this section Summary
Link to this section Functions
Imports app_env/3
and app_env/4
. Additionally generates the function
template(
For now is just equivalent to use import Skogsra
.
Creates a function to retrieve specific environment/application variables values.
The function created is named function_name
and will get the value
associated with an application called app_name
and one or several
parameters
keys. Optionally, receives a list of options
.
Available options:
Option | Type | Default | Description |
---|---|---|---|
default | any | nil | Sets the Default value for the variable. |
type | Skogsra.Env.type() | :binary | Sets the explicit type for the variable. |
os_env | binary | autogenerated | Overrides automatically generated OS environment variable name. |
binding_order | Skogra.Env.bindings() | [:system, :config] | Sets the load order for variable binding. |
binding_skip | Skogra.Env.bindings() | [] | Which variable bindings should be skipped. |
required | boolean | false | Whether the variable is required or not. |
cached | boolean | true | Whether the variable should be cached or not. |
namespace | module | nil | Overrides any namespace. |
e.g:
For the following declaration:
app_env :db_password, :myapp, [:mydb, :password],
default: "password",
will generate:
db_password/0
anddb_password/1
for getting the variable's value without or with namespace respectively. It returns:ok
and:error
tuples.db_password!/0
anddb_password!/1
for getting the variable's value without or with namespace respectively. It fails on error.reload_db_password/0
andreload_db_password/1
for reloading the variable's value in the cache without or with namespace respectively.put_db_password/1
andput_db_password/2
for settings a new value for the variable directly to the cache without or with namespace respectively.
A call to db_password/0
will try to get a value:
- From the OS environment variable
$MYAPP_MYDB_PASSWORD
(can be overriden by the optionos_env
). From the configuration file e.g:
config :myapp, mydb: [password: "some password"]
- From the default value if it exists (In this case, it would return
"password"
).
A call to db_password/1
with namespace Test
will try to get a value:
- From the OS environment variable
$TEST_MYAPP_MYDB_PASSWORD
. From the configuration file e.g:
config :myapp, Test, mydb: [password: "some test password"]
- From the OS environment variable
$MYAPP_MYDB_PASSWORDT
. From the configuraton file e.g:
config :myapp, mydb: [password: "some password"]
- From the default value if it exists. In our example,
"password"
.