View Source Pipeline.State (ex_pipeline v0.2.0)

Pipeline state management.

This module defines a struct that is used to keep track of the state of a pipeline: the initial value, the current value, it's still valid (or not) and any error that may have occurred.

It also has functions to create and manipulate a state.

You probably won't need to interact with this module too often, since it's all managed by the pipeline engine. The only part of a pipeline where this module is accessible is on callback functions.

Link to this section Summary

Types

t()

A struct that wraps metadata information about a pipeline.

Functions

Marks the given state as invalid.

Marks the given state as invalid and adds an error to the state.

Creates a new, valid, %Pipeline.State{} struct with the given initial value

Updates a state with the given reducer.

Link to this section Types

@type t() :: %Pipeline.State{
  error: any(),
  executed_steps: [{module(), atom()}],
  initial_value: any(),
  valid?: boolean(),
  value: any()
}

A struct that wraps metadata information about a pipeline.

  • initial_value is the first ever value that is passed to the first step on a pipeline.
  • value is the current value of the pipeline
  • valid? is boolean indicating wether the pipeline is still valid (true) or not (false).
  • error the error that may have happened during the execution of the pipeline.
  • executed_steps a list of all steps that were executed

Link to this section Functions

@spec invalidate(t()) :: t()

Marks the given state as invalid.

Since no errors are specified, the error field on the state becomes a generic error string.

examples

Examples

iex> %Pipeline.State{valid?: true, error: nil} |> Pipeline.State.invalidate()
%Pipeline.State{error: "an error occured during the execution of the pipeline", valid?: false}
Link to this function

invalidate(state, error)

View Source
@spec invalidate(t(), any()) :: t()

Marks the given state as invalid and adds an error to the state.

The error field on the state will have the same value from the given error.

examples

Examples

iex> %Pipeline.State{valid?: true, error: nil} |> Pipeline.State.invalidate(:bad_thing)
%Pipeline.State{error: :bad_thing, valid?: false}
@spec new(any()) :: t()

Creates a new, valid, %Pipeline.State{} struct with the given initial value

examples

Examples

iex> Pipeline.State.new(%{id: 1})
%Pipeline.State{error: nil, executed_steps: [], initial_value: %{id: 1}, valid?: true, value: %{id: 1}}
Link to this function

update(state, transform, options \\ [])

View Source
@spec update(t(), Pipeline.Types.reducer(), Pipeline.Types.options()) :: t()

Updates a state with the given reducer.

If everything goes well and the function returns an ok tuple, it will return an updated %Pipeline.State{} struct.

If the function returns an error tuple, it will call invalidate/1 or invalidate/2 and return an updated and invalid %Pipeline.State{} struct.

Note that the function must return an ok/error tuple, otherwise a Transform.Error error is thrown.