Confispex (confispex v0.5.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 were invoked using get/1.

Returns true if any required variable in specified group was invoked using get/1.

Get a value from store by specified variable name (key) and cast it according to schema.

Merge new store with the existing one overriding existing keys.

Print report with variables usage to STDOUT.

Set context.

Set store unless it is already set.

Set schema.

Link to this section Functions

Link to this function

all_required_touched?(group_name)

Specs

all_required_touched?(group_name :: atom()) :: boolean()

Returns true if all required variables in specified group were invoked using get/1.

Link to this function

any_required_touched?(group_name)

Specs

any_required_touched?(group_name :: atom()) :: boolean()

Returns true if any required variable in specified group was invoked using get/1.

Link to this function

get(variable_name)

Specs

get(variable_name :: any()) :: 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.

Link to this function

merge_store(new_store)

Specs

merge_store(map()) :: :ok

Merge new store with the existing one overriding existing keys.

Useful when updating config in runtime.

Example

Confispex.merge_store(Jason.decode!(File.read!("config.json")))

Specs

report(:detailed | :brief) :: :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.

Link to this function

set_context(context)

Specs

set_context(map()) :: :ok

Set context.

Most likely you'll want to setup env and target:

Example

Confispex.set_context(%{env: config_env(), target: config_target()})
Link to this function

set_new_store(store)

Specs

set_new_store(map()) :: :ok

Set store unless it is already set.

Example

Confispex.set_new_store(System.get_env())
Link to this function

set_schema(schema)

Specs

set_schema(module()) :: :ok

Set schema.