RuntimeCheck.DSL (runtime_check v0.1.0)
View SourceUtility functions for creating checks.
Summary
Functions
Creates an application variable check.
Creates a basic check.
Creates a basic check with a function and a list of nested checks.
Creates a environment variable check.
Creates a feature flag check.
Creates a feature flag check.
Types
@type checker_or_list() :: RuntimeCheck.Check.checker() | [RuntimeCheck.Check.t()]
Functions
Creates an application variable check.
The third argument can be either an atom or a list of atoms. If it's a list, the first element is used as key for Application.fetch_env/2 and the rest looked up using get_in, so the value should implement the Access protocol.
The check fails when the config is not present or results in a nil value.
A list of invalid values can be passed as opts
like reject: [""]
. If value of the variable
is any of the list, the check fails.
@spec check(atom(), checker_or_list()) :: RuntimeCheck.Check.t()
Creates a basic check.
It can be called using:
check(name, function)
check(name, list)
check(name, function, list)
When the second argument is a function with arity 0, it should return:
:ok
or{:ok, term()}
when the check passes. Nested checks are executed.:ignore
when the check is ignored, nested checks are ignored too.{:error, term()}
when the check fails. Nested checks are not executed.
When the second or third argument is a list of checks, they are executed in order and only if the parent check initally passes.
When the check has nested checks, the parent check only passes if all nested checks either pass or are ignored. When there are no nested checks, the check passes immediately.
@spec check(atom(), RuntimeCheck.Check.checker(), [RuntimeCheck.Check.t()]) :: RuntimeCheck.Check.t()
Creates a basic check with a function and a list of nested checks.
See check/2
for more info.
@spec env_var(String.t(), [{:allow_empty, boolean()}] | []) :: RuntimeCheck.Check.t()
Creates a environment variable check.
The name of the environment variable is used as the name of the check.
The check fails when the variable is not present or when it's empty, unless allow_empty: true
is given in the opts.
This check is intended to be used as a nested check, as always-required variables should be enfored in config/runtime.exs
, not here.
@spec feature_check(atom(), checker_or_list()) :: RuntimeCheck.Check.t()
Creates a feature flag check.
The name of the check is used as the feature flag name as well. The function and/or nested checks are only executed if the feature is enabled using a boolean gate. If not, the check is ignored.
The second and third argument behave like check/2-3
. See check/2
for more info.
@spec feature_check(atom(), RuntimeCheck.Check.checker(), [RuntimeCheck.Check.t()]) :: RuntimeCheck.Check.t()
Creates a feature flag check.
See feature_check/2
for more info.