PipelineFlow.Helpers (PipelineFlow v0.4.0)
Helpers module for PipelineFlow structs. All these functions are also imported when you use the PiplineFlow macro.
Summary
Functions
Adds a warning
Tests if the given steps on the PiplineFlow struct are completed
Checks if PiplineFlow was executed correctly
Transforms PipelineFlow in map of attributes
Halts execution of flow
Checks if the PipelineFlow has halted execution
Logs the state of a given PipelineFlow struct
Checks if PiplineFlow was executed correctly
Parses the result of a PiplineFlow struct. Returns {:ok, any()}
when pipeline.
Depending on the implementation of the PipelineFlow struct, the result will be that struct itself,
the value set in the struct or the value that is returned from the value(PipelineFlow.t())
function
that is implemented on the module.
Sets attribute on PipelineFlow module struct
Adds completed step to list
Sets last encountered error of PipelineFlow struct
Sets last performed step of PipelineFlow struct
Sets a parent PipelineFlow to the child PipelineFlow. Can be used when you are using a string of flows that are dependent of each other.
Returns the current status of a pipeline. Can be either be :ok, :error or :halt
Tests if given step is defined on PipelineFlow struct
Functions
add_warning(pipeline, step, warning)
@spec add_warning(PipelineFlow.pipeline(), atom(), any()) :: PipelineFlow.pipeline()
Adds a warning
Examples
iex> pipeline = %TestPipeline{}
...> pipeline.warnings
[]
iex> pipeline = PipelineFlow.Helpers.add_warning(pipeline, :first_step, "A warning")
...> pipeline.warnings
[{:first_step, "A warning"}]
allows_exec?(pipeline_mod)
completed?(pipeline, step)
@spec completed?(PipelineFlow.pipeline(), PipelineFlow.step() | [PipelineFlow.step()]) :: boolean()
Tests if the given steps on the PiplineFlow struct are completed
Examples
iex> PipelineFlow.Helpers.completed?(%TestPipeline{}, [:result_tuple_on_argument])
false
iex> PipelineFlow.Helpers.completed?(%TestPipeline{}, :result_tuple_on_argument)
false
iex> PipelineFlow.Helpers.completed?(%TestPipeline{completed_steps: [:result_tuple_on_argument]}, [:result_tuple_on_argument])
true
iex> PipelineFlow.Helpers.completed?(%TestPipeline{completed_steps: [:result_tuple_on_argument]}, :result_tuple_on_argument)
true
error?(pipeline)
@spec error?(PipelineFlow.pipeline()) :: boolean()
Checks if PiplineFlow was executed correctly
Examples
iex> PipelineFlow.Helpers.error?(%TestPipeline{error: :faulty})
true
iex> PipelineFlow.Helpers.error?(%TestPipeline{})
false
exec(pipeline)
@spec exec(PipelineFlow.pipeline()) :: {:ok, any()} | {:error, atom(), any()}
get_attributes(pipeline)
@spec get_attributes(PipelineFlow.pipeline()) :: map()
Transforms PipelineFlow in map of attributes
iex> PipelineFlow.Helpers.get_attributes(%TestPipeline{some_attribute: "foobar", list_attribute: ["1", "2", "3"]}) %{some_attribute: "foobar", list_attribute: ["1", "2", "3"]}
halt(pipeline)
@spec halt(PipelineFlow.pipeline()) :: PipelineFlow.pipeline()
Halts execution of flow
Examples
iex> pipeline = %TestPipeline{}
%TestPipeline{}
iex> pipeline = PipelineFlow.Helpers.halt(pipeline)
...> PipelineFlow.Helpers.halted?(pipeline)
true
halted?(pipeline)
@spec halted?(PipelineFlow.pipeline()) :: boolean()
Checks if the PipelineFlow has halted execution
Examples
iex> PipelineFlow.Helpers.halted?(%TestPipeline{})
false
iex> PipelineFlow.Helpers.halted?(%TestPipeline{} |> PipelineFlow.Helpers.halt())
true
log(pipeline)
@spec log(PipelineFlow.pipeline()) :: PipelineFlow.pipeline()
Logs the state of a given PipelineFlow struct
ok?(pipeline)
@spec ok?(PipelineFlow.pipeline()) :: boolean()
Checks if PiplineFlow was executed correctly
Examples
iex> PipelineFlow.Helpers.ok?(%TestPipeline{})
true
iex> PipelineFlow.Helpers.ok?(%TestPipeline{error: :faulty})
false
result(pipeline)
@spec result(PipelineFlow.pipeline()) :: {:ok, PipelineFlow.pipeline()} | {:error, :atom, term()}
Parses the result of a PiplineFlow struct. Returns {:ok, any()}
when pipeline.
Depending on the implementation of the PipelineFlow struct, the result will be that struct itself,
the value set in the struct or the value that is returned from the value(PipelineFlow.t())
function
that is implemented on the module.
didn't encountered an error. Returns {:error, atom(), any()}
(where atom()
is the step where the error eccoured)
Examples
iex> PipelineFlow.Helpers.result(%TestPipeline{})
{:ok, %TestPipeline{}}
iex> PipelineFlow.Helpers.result(%TestPipeline{value: "some-value"})
{:ok, "some-value"}
iex> PipelineFlow.Helpers.result(%TestPipeline2{some_attribute: "value-returned-from-value-function"})
{:ok, "value-returned-from-value-function"}
iex> PipelineFlow.Helpers.result(%TestPipeline{error: :faulty, last_step: :get_data})
{:error, :get_data, :faulty}
set_attribute(pipeline, attrs)
@spec set_attribute(PipelineFlow.pipeline(), map() | nil) :: PipelineFlow.pipeline()
Sets attribute on PipelineFlow module struct
Examples
iex> %TestPipeline{}
%TestPipeline{some_attribute: nil}
iex> PipelineFlow.Helpers.set_attribute(%TestPipeline{}, :some_attribute, "foobar")
%TestPipeline{some_attribute: "foobar"}
iex> PipelineFlow.Helpers.set_attribute(%TestPipeline{}, :non_existing_field, "foobar")
%TestPipeline{}
iex> PipelineFlow.Helpers.set_attribute(%TestPipeline{}, %{some_attribute: "foobar"})
%TestPipeline{some_attribute: "foobar"}
iex> PipelineFlow.Helpers.set_attribute(%TestPipeline{}, %{non_existing_field: "foobar"})
%TestPipeline{}
set_attribute(pipeline, key, value)
@spec set_attribute(PipelineFlow.pipeline(), atom(), any()) :: PipelineFlow.pipeline()
set_completed_step(pipeline, step)
@spec set_completed_step(PipelineFlow.pipeline(), atom()) :: PipelineFlow.pipeline()
Adds completed step to list
Examples
iex> pipeline = %TestPipeline{}
...> pipeline.completed_steps
[]
iex> pipeline = PipelineFlow.Helpers.set_completed_step(pipeline, :result_tuple_on_argument)
...> pipeline.completed_steps
[:result_tuple_on_argument]
iex> pipeline = PipelineFlow.Helpers.set_completed_step(pipeline, :non_existing_step)
...> pipeline.completed_steps
[:result_tuple_on_argument]
set_error(pipeline, error)
@spec set_error(PipelineFlow.pipeline(), nil | any()) :: PipelineFlow.pipeline()
Sets last encountered error of PipelineFlow struct
set_last_step(pipeline, step)
Sets last performed step of PipelineFlow struct
Examples
iex> PipelineFlow.Helpers.set_last_step(%TestPipeline{}, :result_tuple_pipeline_return_value)
%TestPipeline{last_step: :result_tuple_pipeline_return_value}
iex> PipelineFlow.Helpers.set_last_step(%TestPipeline{}, :step_does_not_exist)
%TestPipeline{}
set_parent(pipeline, parent)
@spec set_parent(PipelineFlow.pipeline(), nil | PipelineFlow.pipeline()) :: PipelineFlow.pipeline()
Sets a parent PipelineFlow to the child PipelineFlow. Can be used when you are using a string of flows that are dependent of each other.
Examples
iex> pipeline = %TestPipeline{}
...> pipeline.parent
nil
iex> other_pipeline = %TestPipeline2{}
...>
...> PipelineFlow.Helpers.set_parent(pipeline, other_pipeline)
%TestPipeline{parent: %TestPipeline2{}}
set_result(pipeline, step, result)
@spec set_result(PipelineFlow.pipeline(), atom(), any()) :: any()
status(pipeline)
@spec status(PipelineFlow.pipeline()) :: atom()
Returns the current status of a pipeline. Can be either be :ok, :error or :halt
Examples
iex> PipelineFlow.Helpers.status(%TestPipeline{})
:ok
iex> PipelineFlow.Helpers.status(%TestPipeline{error: :faulty})
:error
iex> PipelineFlow.Helpers.status(%TestPipeline{halted: true})
:halt
iex> PipelineFlow.Helpers.status(%TestPipeline{error: :faulty, halted: true})
:halt
step_defined?(pipeline_mod, step)
@spec step_defined?(PipelineFlow.pipeline_mod(), PipelineFlow.step()) :: boolean()
Tests if given step is defined on PipelineFlow struct
Examples
iex> PipelineFlow.Helpers.step_defined?(TestPipeline, :get_products)
false
iex> PipelineFlow.Helpers.step_defined?(TestPipeline, :result_tuple_on_argument)
true