Confispex (confispex v1.1.0)
A tool which allows to define specs for runtime configuration, cast values according to specified types and inspect them.
Link to this section Summary
Functions
Returns true
if all required variables in specified group are present in store.
Returns true
if any required variable in specified group is present in store.
Get a value from store by specified variable name (key) and cast it according to schema.
Initialize or reinitialize a state in server
Initialize a state in server if it hasn't already been initialized
Print report with variables usage to STDOUT.
Update a store
Link to this section Types
context()
Specs
store()
Specs
store() :: map()
Link to this section Functions
all_required_touched?(group_name, server \\ Confispex.Server)
Specs
all_required_touched?(group_name :: atom(), GenServer.server()) :: boolean()
Returns true
if all required variables in specified group are present in store.
any_required_touched?(group_name, server \\ Confispex.Server)
Specs
any_required_touched?(group_name :: atom(), GenServer.server()) :: boolean()
Returns true
if any required variable in specified group is present in store.
If variable is present, then it means you was trying to configure the group. This is needed for conditional configuration of applications that may shutdown the system if you try to configure the application with invalid params.
Example
if Confispex.any_required_touched?(:apns) do
config :pigeon, :apns,
sandbox: %{
cert: Confispex.get("APNS_CERT"),
key: Confispex.get("APNS_KEY"),
mode: :dev
}
end
get(variable_name, server \\ Confispex.Server)
Specs
get(Confispex.Schema.variable_name(), GenServer.server()) :: any()
Get a value from store by specified variable name (key) and cast it according to schema.
Example
config :my_app, MyApp.Repo, url: Confispex.get("DATABASE_URL")
In case of any error during casting nil
is returned, errors are saved and can be
retrieved later using report/1
function.
init(params, server \\ Confispex.Server)
Specs
init( %{ :schema => module(), :context => context(), optional(:store) => store() | (() -> store()) }, GenServer.server() ) :: :ok
Initialize or reinitialize a state in server
Example
Confispex.init(%{
schema: MyApp.RuntimeConfigSchema,
context: %{env: config_env(), target: config_target()}
})
By default, Confispex
uses System.get_env/0
to setup the store.
init_once(params, server \\ Confispex.Server)
Specs
init_once( %{ :schema => module(), :context => context(), optional(:store) => store() | (() -> store()) }, GenServer.server() ) :: :ok
Initialize a state in server if it hasn't already been initialized
Example
Confispex.init(%{
schema: MyApp.RuntimeConfigSchema,
context: %{env: config_env(), target: config_target()}
})
By default, Confispex
uses System.get_env/0
to setup the store.
report(mode, server \\ Confispex.Server)
Specs
report(:detailed | :brief, GenServer.server()) :: :ok
Print report with variables usage to STDOUT.
The difference between :detailed
and :brief
modes is that :brief
doesn't print values of the store.
Use :brief
if you don't want to show sensitive data.
Example
Confispex.report(:detailed)
update_store(update_fn, server \\ Confispex.Server)
Specs
update_store((store() -> store()), GenServer.server()) :: :ok
Update a store
Example
new_store = %{...}
Confispex.update_store(&Map.merge(&1, new_store))