Helios v0.2.2 Helios.Context View Source

Represent execution context for single message/command sent to helios endpoint.

Link to this section Summary

Functions

Assigns a value to a key in the context

Emits given event or events. If events is equal to nil, then it will ignore call

Halts the Context pipeline by preventing further plugs downstream from being invoked. See the docs for Helios.Context.Builder for more information on halting a command context pipeline

Assigns multiple values to keys in the context

Assigns multiple private keys and values in the context

Assigns a new private key and value in the context

Link to this section Types

Link to this type aggregate_module() View Source
aggregate_module() :: module()
Link to this type assigns() View Source
assigns() :: %{optional(atom()) => any()}
Link to this type correlation_id() View Source
correlation_id() :: String.t() | nil
Link to this type events() View Source
events() :: nil | event() | [event()]
Link to this type opts() View Source
opts() ::
  binary()
  | tuple()
  | atom()
  | integer()
  | float()
  | [opts()]
  | %{optional(opts()) => opts()}
Link to this type params() View Source
params() :: map() | struct()
Link to this type private() View Source
private() :: map()
Link to this type request_id() View Source
request_id() :: String.t()
Link to this type response() View Source
response() :: any()
Link to this type status() View Source
status() :: :init | :executing | :executed | :commiting | :success | :failed
Link to this type t() View Source
t() :: %Helios.Context{
  adapter: {module(), term()},
  assigns: assigns(),
  before_send: list(),
  correlation_id: correlation_id(),
  events: events(),
  halted: halted(),
  handler: term(),
  method: atom(),
  owner: owner(),
  params: params(),
  path_info: [binary()],
  path_params: params(),
  peer: peer(),
  private: private(),
  request_id: request_id(),
  response: response(),
  retry: integer(),
  state: :unset | :set | :sent,
  status: status()
}

Link to this section Functions

Assigns a value to a key in the context.

Examples

iex> ctx.assigns[:hello]
nil
iex> ctx = assign(ctx, :hello, :world)
iex> ctx.assigns[:hello]
:world

Emits given event or events. If events is equal to nil, then it will ignore call.

Halts the Context pipeline by preventing further plugs downstream from being invoked. See the docs for Helios.Context.Builder for more information on halting a command context pipeline.

Link to this function merge_assigns(ctx, keyword) View Source
merge_assigns(Helios.Context.t(), Keyword.t()) :: Helios.Context.t()

Assigns multiple values to keys in the context.

Equivalent to multiple calls to assign/3.

Examples

iex> ctx.assigns[:hello]
nil
iex> ctx = merge_assigns(ctx, hello: :world)
iex> ctx.assigns[:hello]
:world
Link to this function merge_private(ctx, keyword) View Source
merge_private(Helios.Context.t(), Keyword.t()) :: Helios.Context.t()

Assigns multiple private keys and values in the context.

Equivalent to multiple put_private/3 calls.

Examples

iex> ctx.private[:plug_hello]
nil
iex> ctx = merge_private(ctx, plug_hello: :world)
iex> ctx.private[:plug_hello]
:world
Link to this function put_private(ctx, key, value) View Source
put_private(Helios.Context.t(), atom(), term()) :: Helios.Context.t()

Assigns a new private key and value in the context.

This storage is meant to be used by libraries and frameworks to avoid writing to the user storage (the :assigns field). It is recommended for libraries/frameworks to prefix the keys with the library name.

For example, if some plug needs to store a :hello key, it should do so as :plug_hello:

iex> ctx.private[:plug_hello]
nil
iex> ctx = put_private(ctx, :plug_hello, :world)
iex> ctx.private[:plug_hello]
:world
Link to this function send_resp(ctx) View Source
send_resp(t()) :: t() | no_return()