RuntimeCheck.DSL (runtime_check v0.1.0)

View Source

Utility functions for creating checks.

The most basic functions are check/2 and check/3.

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

checker_or_list()

@type checker_or_list() :: RuntimeCheck.Check.checker() | [RuntimeCheck.Check.t()]

Functions

app_var(name, otp_app, key_or_keys, opts \\ [])

@spec app_var(atom(), atom(), atom() | [atom()], Keyword.t()) ::
  RuntimeCheck.Check.t()

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.

check(name, checker)

@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.

check(name, checker, nested_checks)

Creates a basic check with a function and a list of nested checks.

See check/2 for more info.

env_var(var_name, opts \\ [])

@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.

feature_check(name, fun)

@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.

feature_check(name, fun, nested_checks)

Creates a feature flag check.

See feature_check/2 for more info.