conform v2.5.2 Conform.Conf

This module is exposed to schemas for usage in transformations, it contains utility functions for fetching configuration information from the current config state.

Summary

Functions

Selects key/value pairs from the conf table which match the provided key, or are a child of the provided key. Keys can contain variables expressed as $varname, which act as wildcards for that element of the key

Parses a .conf from the provided binary, does some initial validation and reformatting, and dumps it into an ETS table for further processing. The table identifier is returned, but the preferred method for manipulating/querying the conf terms is via this module’s API

Parses a .conf located at the provided path, does some initial validation and reformatting, and dumps it into an ETS table for further processing. The table identifier is returned, but the preferred method for manipulating/querying the conf terms is via this module’s API

Selects all keys which match the provided fuzzy search

Selects key/value pairs from the conf table which match the provided key exactly, or match the provided key+variables exactly. Keys with variables (expressed as $varname), act as wildcards for that element of the key, so they can match more than a single setting

Given a string or atom of the form some.path.to.a.setting, it breaks it into a list of it’s component parts, ensuring that embedded module names are preserved, and that the Elixir prefix is added if missing and applicable

Removes any key/value pairs from the conf table which match the provided key or are a child of the provided key

Functions

find(table, key)
find(non_neg_integer | atom, String.t | [charlist]) :: [{[atom], term}]

Selects key/value pairs from the conf table which match the provided key, or are a child of the provided key. Keys can contain variables expressed as $varname, which act as wildcards for that element of the key.

Results are returned in the form of {key, value} where key is the full key of the setting.

Examples

iex> table = :ets.new(:test, [:set, keypos: 1])
...> :ets.insert(table, {['lager', 'handlers', 'console', 'level'], :info})
...> :ets.insert(table, {['lager', 'handlers', 'file', 'error'], '/var/log/error.log'})
...> Elixir.Conform.Conf.find(table, "lager.handlers.$backend.level")
[{['lager', 'handlers', 'console', 'level'], :info}]
...> Elixir.Conform.Conf.get(table, "lager.handlers.$backend")
[{['lager', 'handlers', 'console', 'level'], :info},
 {['lager', 'handlers', 'file', 'error'], '/var/log/error.log'}]
from_binary(conf)
from_binary(binary) ::
  {:error, term} |
  {:ok, non_neg_integer | atom}

Parses a .conf from the provided binary, does some initial validation and reformatting, and dumps it into an ETS table for further processing. The table identifier is returned, but the preferred method for manipulating/querying the conf terms is via this module’s API.

from_file(path)
from_file(String.t) ::
  {:error, term} |
  {:ok, non_neg_integer | atom}

Parses a .conf located at the provided path, does some initial validation and reformatting, and dumps it into an ETS table for further processing. The table identifier is returned, but the preferred method for manipulating/querying the conf terms is via this module’s API.

fuzzy_get(table, key)

Selects all keys which match the provided fuzzy search.

Examples

iex> table = :ets.new(:test, [:set, keypos: 1])
...> :ets.insert(table, {['lager', 'handlers', 'console', 'level'], :info})
...> :ets.insert(table, {['lager', 'handlers', 'file', 'error'], '/var/log/error.log'})
...> Elixir.Conform.Conf.fuzzy_get(table, "lager.handlers.*")
[{['lager', 'handlers', 'console', 'level'], :info}]
...> Elixir.Conform.Conf.fuzzy_get(table, "lager.handlers.$backend")
[{['lager', 'handlers', 'console', 'level'], :info},
{['lager', 'handlers', 'file', 'error'], '/var/log/error.log'}]
get(table, key)
get(non_neg_integer | atom, String.t | [charlist]) ::
  [{[atom], term}] |
  {:error, term}

Selects key/value pairs from the conf table which match the provided key exactly, or match the provided key+variables exactly. Keys with variables (expressed as $varname), act as wildcards for that element of the key, so they can match more than a single setting.

Results are returned in the form of {key, value} where key is the full key of the setting.

Examples

iex> table = :ets.new(:test, [:set, keypos: 1])
...> :ets.insert(table, {['lager', 'handlers', 'console', 'level'], :info})
...> :ets.insert(table, {['lager', 'handlers', 'file', 'error'], '/var/log/error.log'})
...> Elixir.Conform.Conf.get(table, "lager.handlers.console.level")
[{['lager', 'handlers', 'console', 'level'], :info}]
...> Elixir.Conform.Conf.get(table, "lager.handlers.$backend.$setting")
[{['lager', 'handlers', 'console', 'level'], :info},
 {['lager', 'handlers', 'file', 'error'], '/var/log/error.log'}]
get_key_path(key)

Given a string or atom of the form some.path.to.a.setting, it breaks it into a list of it’s component parts, ensuring that embedded module names are preserved, and that the Elixir prefix is added if missing and applicable:

Example

"myapp.Some.Module.setting" => ['myapp', 'Elixir.Some.Module', 'setting']
remove(table, key)
remove(non_neg_integer | atom, String.t | [charlist]) :: :ok

Removes any key/value pairs from the conf table which match the provided key or are a child of the provided key.