Juggernaut.Config.Loader (Juggernaut v0.4.0)

Copy Markdown View Source

Reads and checks .juggernaut.exs (see the configuration guide).

Checked in this order, each failure a config error naming the file:

  1. the file evaluates (syntax errors, raises, throws and exits are reported, never crash the task);
  2. the result is a keyword list;
  3. no key is given twice, at the top level or inside a nested group (checked before NimbleOptions, whose message for that case is unknown options);
  4. NimbleOptions validation: unknown keys reported together, nested errors with their path.

Summary

Functions

Checks an evaluated config term and validates it against the schema.

A config error whose message names the config file.

The config file name, relative to the project root.

Reads the config of the project at root: {:ok, options, path} with defaults filled (path is nil when there is no file), or a config error.

Evaluates path; a missing file is an empty keyword list.

Functions

check(term)

@spec check(term()) :: {:ok, keyword()} | {:error, Juggernaut.Error.t()}

Checks an evaluated config term and validates it against the schema.

error(message, details \\ %{})

@spec error(String.t(), map()) :: Juggernaut.Error.t()

A config error whose message names the config file.

file_name()

@spec file_name() :: String.t()

The config file name, relative to the project root.

load(root)

@spec load(Path.t()) ::
  {:ok, keyword(), Path.t() | nil} | {:error, Juggernaut.Error.t()}

Reads the config of the project at root: {:ok, options, path} with defaults filled (path is nil when there is no file), or a config error.

read(path)

@spec read(Path.t()) :: {:ok, term()} | {:error, Juggernaut.Error.t()}

Evaluates path; a missing file is an empty keyword list.