Distopy.Source protocol (distopy v0.1.0) View Source

Link to this section Summary

Source group callbacks

Returns the sub-source that defines the key key. The function must return a tuple with group_key as an unique identifier of the sub-source in the group, and the sub-source itself.

Returns a list of sub-sources identified by an unique "group" key.

Replaces the sub-source uniquely identified by group_key. The given group key is the one returned from get_sub_with_key/2 or list_source/1.

Sets the current selected source identified by group_key. A group of sources shoud add new environment variables to the currently selected sub.

Returns wether the currently selected sub-source in group is the given group_key. The group key is the one returned from get_sub_with_key/2 or list_source/1.

Functions

Creates a new environment variable in the source. It will only be called if the source returns true from updatable?/1.

Deletes the environment variable identified by key in the source.

Returns the name of the source for display purposes.

Returns the reprensentation of a value for display purposes. Instead of returning the raw binary value, it is possible to return text like "hidden value", a parsed reprensentation of a JSON string, etc.

Get the value associated to the environment variables identified by key. It should raise if the variable is not defined.

Returns wether the given environment variable is defined in the source.

Returns the list of environment variable names defined in the source.

Represents a single key/value pair for display purposes.

Returns a displayable version of the given list of environment variables keys and values.

Returns wether the source has sub-sources, i.e. is a group of sources.

Returns wether the source can be modified by adding or remomving environment variables.

Link to this section Types

Link to this section Source group callbacks

Link to this function

get_sub_with_key(t, key)

View Source

Specs

get_sub_with_key(t(), key :: binary()) ::
  {group_key :: term(), sub_source :: term()}

Returns the sub-source that defines the key key. The function must return a tuple with group_key as an unique identifier of the sub-source in the group, and the sub-source itself.

Do not mistake key for group_key. The former identifies an environment variable name while the latter identifies a sub-source in a group.

Specs

list_sources(t()) :: [{group_key :: term(), display_name :: iodata()}]

Returns a list of sub-sources identified by an unique "group" key.

Link to this function

put_sub(t, group_key, sub_source)

View Source

Specs

put_sub(t(), group_key :: term(), sub_source :: term()) :: t()

Replaces the sub-source uniquely identified by group_key. The given group key is the one returned from get_sub_with_key/2 or list_source/1.

Link to this function

select_source(t, source)

View Source

Specs

select_source(t(), group_key :: term()) :: t()

Sets the current selected source identified by group_key. A group of sources shoud add new environment variables to the currently selected sub.

Specs

selected?(t(), group_key :: term()) :: boolean()

Returns wether the currently selected sub-source in group is the given group_key. The group key is the one returned from get_sub_with_key/2 or list_source/1.

Link to this section Functions

Specs

add_pair(t(), key :: binary(), value :: binary()) ::
  {:ok, t()} | {:error, binary()}

Creates a new environment variable in the source. It will only be called if the source returns true from updatable?/1.

Specs

delete_key(t(), key :: binary()) :: {:ok, t()} | {:error, binary()}

Deletes the environment variable identified by key in the source.

Specs

display_name(t()) :: iodata()

Returns the name of the source for display purposes.

Specs

display_value(t(), key :: binary()) :: iodata()

Returns the reprensentation of a value for display purposes. Instead of returning the raw binary value, it is possible to return text like "hidden value", a parsed reprensentation of a JSON string, etc.

Specs

get_value(t(), key :: binary()) :: binary()

Get the value associated to the environment variables identified by key. It should raise if the variable is not defined.

Specs

has_key?(t(), key :: binary()) :: boolean()

Returns wether the given environment variable is defined in the source.

Specs

list_keys(t()) :: [binary()]

Returns the list of environment variable names defined in the source.

Link to this function

pair_to_iodata(t, key, value)

View Source

Specs

pair_to_iodata(t(), key :: binary(), value :: iodata()) :: iodata()

Represents a single key/value pair for display purposes.

See pairs_to_iodata/2.

Link to this function

pairs_to_iodata(t, pairs)

View Source

Specs

pairs_to_iodata(t(), [{key :: binary(), value :: iodata()}]) :: iodata()

Returns a displayable version of the given list of environment variables keys and values.

The keys may or may not be defined in the source as the values are passed to the function.

Specs

source_group?(t()) :: boolean()

Returns wether the source has sub-sources, i.e. is a group of sources.

Specs

updatable?(t()) :: boolean()

Returns wether the source can be modified by adding or remomving environment variables.