View Source Luminous.Variable behaviour (luminous v0.9.1)

A variable is defined at compile time and its values are determined at runtime. It also stores a current value that can be updated. A variable value is descriptive in that it contains a label (for display purposes) and the actual value.

Link to this section Summary

Callbacks

A module must implement this behaviour to be passed as an argument to define/3.

Functions

Defines a new variable and returns the struct does not calculate the values yet (see populate/1). The module must implement the Luminous.Variable behaviour.

Extracts and returns the label from the descriptive variable value.

Extract and returns the value from the descriptive variable value.

Find and return the variable with the specified id in the supplied variables.

Returns the variable's current (descriptive) value or nil.

Find the variable with the supplied id in the supplied variables and return its current extracted value.

Uses the query to populate the variables's values and returns the new struct. Additionally, it sets the current value to be the first of the calculated values.

Replaces the variables current value with the new value and returns the new struct. It performs a check whether the supplied value is a valid value (i.e. exists in values). If it's not, then it returns the struct unchanged.

Link to this section Types

@type descriptive_value() :: %{label: binary(), value: binary()}
@type simple_value() :: binary()
@type t() :: %Luminous.Variable{
  current: descriptive_value() | nil,
  id: atom(),
  label: binary(),
  mod: module(),
  values: [descriptive_value()]
}

Link to this section Callbacks

@callback variable(atom()) :: [simple_value() | descriptive_value()]

A module must implement this behaviour to be passed as an argument to define/3.

Link to this section Functions

@spec define(atom(), binary(), module()) :: t()

Defines a new variable and returns the struct does not calculate the values yet (see populate/1). The module must implement the Luminous.Variable behaviour.

@spec extract_label(descriptive_value()) :: binary()

Extracts and returns the label from the descriptive variable value.

@spec extract_value(descriptive_value()) :: binary()

Extract and returns the value from the descriptive variable value.

@spec find([t()], atom()) :: t() | nil

Find and return the variable with the specified id in the supplied variables.

@spec get_current(t()) :: descriptive_value() | nil

Returns the variable's current (descriptive) value or nil.

Link to this function

get_current_and_extract_value(variables, variable_id)

View Source
@spec get_current_and_extract_value([t()], atom()) :: binary()

Find the variable with the supplied id in the supplied variables and return its current extracted value.

@spec populate(t()) :: t()

Uses the query to populate the variables's values and returns the new struct. Additionally, it sets the current value to be the first of the calculated values.

Link to this function

update_current(var, new_value)

View Source
@spec update_current(t(), binary()) :: t()

Replaces the variables current value with the new value and returns the new struct. It performs a check whether the supplied value is a valid value (i.e. exists in values). If it's not, then it returns the struct unchanged.