CFG.Config (cfg_lib v0.1.0) View Source

This module contains top-level functionality for working with CFG. Client code will usually just interact with this module.

Link to this section Summary

Types

t()

This type represents a configuration loaded from CFG source.

Functions

Append or prepend a list of directories to the include path of this configuration.

Return this configuration as a map, recursing into included configurations.

Returns a specification to start this module under a supervisor.

Return a configuration from a file, given its path.

Return a configuration from its source.

Get a value from this configuration by key or path, with an optional default value if not found. If no default is specified and a value isn't found, an error will be returned.

Get the include path of this configuration.

See whether this configuration allows duplicates.

See whether this configuration uses a cache.

See if the specified value is a configuration.

Load this configuration from a file, given its path.

Return a new, empty configuration with specified options.

Set whether this configuration uses a cache.

Set the include path of this configuration to the specified list of directories.

Set whether this configuration allows duplicates.

Set the path from which this configuration was loaded. This is also used to determine the directory searched for included configurations.

Link to this section Types

Specs

t() :: %CFG.Config{
  cache: nil | map(),
  context: nil | map(),
  data: nil | map(),
  error: term(),
  include_path: list(),
  no_duplicates: boolean(),
  parent: nil | pid(),
  path: nil | binary(),
  refs_seen: term(),
  root_dir: nil | binary(),
  scalar_tokens: term(),
  strict_conversions: boolean(),
  string_converter: function()
}

This type represents a configuration loaded from CFG source.

These are its fields:

  • no_duplicates - Whether duplicate keys are allowed. If allowed, newer values for a given key silently overwrite older ones. If not and a duplicate is seen, an error is returned.
  • strict_conversions - Whether conversions of backtick-strings are allowed to fail. If not strict, a failure results in the special string being returned. Otherwise, an error is returned.
  • context - An optional map containing a variable name-to-value mapping.
  • include_path - A list of directories which is searched for included configurations. The directory of the including configuration is searched first.
  • path - The absolute path from where the configuration was loaded.
  • root_dir - The directory containing path.
  • parent - The parent configuration of an included configuration.
  • string_converter - A function which is called with a string and the configuration to perform backtick-string conversion.

Link to this section Functions

Link to this function

add_include(this, path, append \\ true)

View Source

Specs

add_include(pid(), [binary()], boolean()) :: atom()

Append or prepend a list of directories to the include path of this configuration.

Specs

as_dict(pid()) :: {atom(), any()}

Return this configuration as a map, recursing into included configurations.

Returns a specification to start this module under a supervisor.

See Supervisor.

Specs

from_file(binary()) :: {atom(), any()}

Return a configuration from a file, given its path.

Specs

from_source(binary()) :: {atom(), any()}

Return a configuration from its source.

Link to this function

get(this, key, default \\ :MISSING)

View Source

Specs

get(pid(), binary(), any()) :: tuple()

Get a value from this configuration by key or path, with an optional default value if not found. If no default is specified and a value isn't found, an error will be returned.

Specs

get_include(pid()) :: [binary()]

Get the include path of this configuration.

Specs

get_no_duplicates(pid()) :: boolean()

See whether this configuration allows duplicates.

Specs

is_cached(pid()) :: boolean()

See whether this configuration uses a cache.

Specs

is_config(any()) :: boolean()

See if the specified value is a configuration.

Specs

load_file(pid(), binary()) :: {atom(), any()}

Load this configuration from a file, given its path.

Specs

new(map()) :: {atom(), pid()}

Return a new, empty configuration with specified options.

Link to this function

set_cached(this, cached)

View Source

Specs

set_cached(pid(), boolean()) :: no_return()

Set whether this configuration uses a cache.

Specs

set_include(pid(), [binary()]) :: atom()

Set the include path of this configuration to the specified list of directories.

Link to this function

set_no_duplicates(this, no_dupes)

View Source

Specs

set_no_duplicates(pid(), boolean()) :: atom()

Set whether this configuration allows duplicates.

Specs

set_path(pid(), binary()) :: atom()

Set the path from which this configuration was loaded. This is also used to determine the directory searched for included configurations.