View Source Plumbery.Request (plumbery v0.1.0)
Requests hold shared state and execution result. As the request moves through the pipeline, it can be modified and later used in next steps down the pipeline.
Requests are expected to be structs with at least the following fields:
command
is a map or struct that contains the arguments for pipelinecontext
contains information about calling context and can be used, for example, for authorizationassigns
a map with shared stateresult
contains pipe execution resulthalted?
true if pipeline is halted
Defining a request struct
Plumbery.Request
is a struct that can in many cases be used as a request for pipelines.
In cases when you need additional fields in your requests, you can use Plumbery.Request
to define the struct.
To define a request struct, create a module and use Plumbery.Request
,
passing a keyword list with additional fields and their default values.
defmodule MyApp.Request do
@enforce_keys [:field1]
use Plumbery.Request, field1: nil, field2: false
end
Summary
Functions
Adds an error and sets result to {:error, errors}
where errors
is a list.
Assigns a value to a key in the request's shared state map.
Sets result to {:error, error}
.
Halts the pipeline. No further steps will be executed.
Sets result to res
. Further steps in the pipeline will be
executed and can further modify the result.
Sets result to {:ok, result}
. Further steps in the pipeline will be
executed and can further modify the result.
Returns request's result
field.
Types
Functions
Adds an error and sets result to {:error, errors}
where errors
is a list.
If key
is nil
, error
will be added to the list, otherwise {key, error}
tuple will be added.
Assigns a value to a key in the request's shared state map.
Sets result to {:error, error}
.
Halts the pipeline. No further steps will be executed.
Sets result to res
. Further steps in the pipeline will be
executed and can further modify the result.
When strict
is true (the default), only {:error, _} and {:ok, _} tuples are
accepted, otherwise any value can be passed.
result, not request, is the first argument intentionally. It allows for this type of calls:
some_function(req.command)
|> result(req)
Sets result to {:ok, result}
. Further steps in the pipeline will be
executed and can further modify the result.
Returns request's result
field.