View Source Luminous.Variable behaviour (luminous v2.2.0)

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 a map. The following options can be passed

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.

Returns the label based on the variable type and current value selection

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 map. 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 map unchanged. The special "none" case is for when the variable's type is :multi and none of the values are selected (empty list)

Link to this section Types

@type descriptive_value() :: %{label: binary(), value: binary()}
@type simple_value() :: binary()
@type t() :: map()

Link to this section Callbacks

@callback variable(atom(), map()) :: [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!(keyword()) :: t()

Defines a new variable and returns a map. The following options can be passed:

  • :id (atom/0) - Required.

  • :label (String.t/0) - Required.

  • :module (atom/0) - Required.

  • :type - The default value is :single.

@spec extract_value(descriptive_value()) :: binary() | [binary()] | nil

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() | [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() | [binary()] | nil

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

@spec get_current_label(t()) :: binary() | nil

Returns the label based on the variable type and current value selection

@spec populate(t(), map()) :: 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(), nil | binary() | [binary()]) :: t()

Replaces the variables current value with the new value and returns the map. 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 map unchanged. The special "none" case is for when the variable's type is :multi and none of the values are selected (empty list)