PipelineFlow.Helpers (PipelineFlow v0.2.0)

Helpers module for PipelineFlow structs. All these functions are also imported when you use the PiplineFlow macro.

Summary

Functions

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

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

Link to this function

allows_exec?(pipeline_mod)

@spec allows_exec?(atom()) :: boolean()
Link to this function

completed?(pipeline, step)

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
Link to this function

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
@spec exec(PipelineFlow.pipeline()) :: {:ok, any()} | {:error, atom(), any()}
Link to this function

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"]}

Halts execution of flow

Examples

iex> pipeline = %TestPipeline{}
%TestPipeline{}
iex> pipeline = PipelineFlow.Helpers.halt(pipeline)
...> PipelineFlow.Helpers.halted?(pipeline)
true
Link to this function

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
Link to this macro

is_pipeline(pipeline)

(macro)
Link to this macro

is_pipeline_module(pipeline)

(macro)
Link to this macro

is_step(step)

(macro)
@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
Link to this function

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}
Link to this function

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{}
Link to this function

set_attribute(pipeline, key, value)

@spec set_attribute(PipelineFlow.pipeline(), atom(), any()) :: PipelineFlow.pipeline()
Link to this function

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]
Link to this function

set_error(pipeline, error)

@spec set_error(PipelineFlow.pipeline(), nil | any()) :: PipelineFlow.pipeline()

Sets last encountered error of PipelineFlow struct

Link to this function

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{}
Link to this function

set_parent(pipeline, parent)

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{}}
Link to this function

set_result(pipeline, step, result)

@spec set_result(PipelineFlow.pipeline(), atom(), any()) :: any()
Link to this function

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
Link to this function

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