View Source Luminous.Variable behaviour (luminous v0.1.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 the struct does not calculate the values yet (see populate/1 below) the module must implement the Variable behaviour
extract the label from the descriptive variable value
extract 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 var's values and returns the new struct also 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 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 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
defines a new variable and returns the struct does not calculate the values yet (see populate/1 below) the module must implement the Variable behaviour
@spec extract_label(descriptive_value()) :: binary()
extract the label from the descriptive variable value
@spec extract_value(descriptive_value()) :: binary()
extract the value from the descriptive variable value
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)
find the variable with the supplied id in the supplied variables and return its current extracted value
uses the query to populate the var's values and returns the new struct also 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 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