FusionDSL v0.0.1-dev FusionDsl.Impl behaviour View Source
Implementation module for FusionDsl. This module helps with developing packages for fusion dsl.
Read packages docs for more info.
Link to this section Summary
Functions
Gets the value of an assign with given key,
:error
in case of unset key
Returns value of a variable in environment
Ensures that all asts in arguments (such as functions values in args) are converted to terms (raw values)
Puts or updates value of a key of assigns in environment
Callbacks
Should return list of function names this package provides as atoms
Link to this section Functions
get_assign(FusionDsl.Runtime.Environment.t(), atom() | String.t()) :: {:ok, any()} | :error
Gets the value of an assign with given key,
:error
in case of unset key
get_var(FusionDsl.Runtime.Environment.t(), String.t()) :: {:ok, any(), FusionDsl.Runtime.Environment.t()}
Returns value of a variable in environment
prep_arg(FusionDsl.Runtime.Environment.t(), list() | any()) :: {:ok, list() | any(), FusionDsl.Runtime.Environment.t()}
Ensures that all asts in arguments (such as functions values in args) are converted to terms (raw values)
For example an argument list may look like: args=[1, {:rand, [ln: 2], [5, 10]}]
When called with prep_arg(env, args) the output of prep_args will be:
{:ok, [1, 6], env}
Parameters
- args: list of arguments or just one argument
- env: the Environment struct
put_assign(FusionDsl.Runtime.Environment.t(), atom() | String.t(), any()) :: FusionDsl.Runtime.Environment.t()
Puts or updates value of a key of assigns in environment.
Every package in Fusion can have their assigns in the runtime environment of script (Somehow like assigns in plug).
The assigns are not accessible directly by fusion code and is meant for packages to hold any elixir data type in them.
Keys
Keys of assigns are recommended to be atoms which start with projects short
otp name. e.g. :fusion_dsl_assgn1
Values
Values of the assigns can be any elixir data type. But putting large amounts of data into assigns is not recommended.
Examples
# Put some value into environment assigns
env = FusionDsl.Impl.put_assign(env, :fusion_dsl_engine_state, :rocks)
%Environment{...}
# Get that value from environment assigns
FusionDsl.Impl.get_assign(env, :fusion_dsl_engine_state)
{:ok, :rocks}
Link to this section Callbacks
__list_fusion_functions__() :: [atom()]
Should return list of function names this package provides as atoms.
Example
@impl true
def __list_fusion_functions__, do: [:foo, :bar]