Axn.Context (Axn v0.2.0)
View SourceContext struct that flows through the step pipeline, carrying request data,
user information, and any step-added fields. Provides helper functions
similar to Plug.Conn and Phoenix.Component.
Summary
Functions
Assigns multiple values from a map or keyword list to the context assigns.
Assigns a value to a key in the context assigns.
Gets a value from the private storage of the context.
Gets a value from the private storage of the context with a default.
Updates the params in the context.
Puts a value in the private storage of the context.
Updates the result in the context.
Types
Functions
Assigns multiple values from a map or keyword list to the context assigns.
Examples
iex> ctx = %Axn.Context{}
iex> updated_ctx = Axn.Context.assign(ctx, %{current_user: %{id: 123}, theme: "dark"})
iex> updated_ctx.assigns
%{current_user: %{id: 123}, theme: "dark"}
iex> ctx = %Axn.Context{}
iex> updated_ctx = Axn.Context.assign(ctx, current_user: %{id: 123}, theme: "dark")
iex> updated_ctx.assigns
%{current_user: %{id: 123}, theme: "dark"}
Assigns a value to a key in the context assigns.
Examples
iex> ctx = %Axn.Context{}
iex> updated_ctx = Axn.Context.assign(ctx, :current_user, %{id: 123})
iex> updated_ctx.assigns
%{current_user: %{id: 123}}
Gets a value from the private storage of the context.
Examples
iex> ctx = %Axn.Context{private: %{correlation_id: "abc123"}}
iex> Axn.Context.get_private(ctx, :correlation_id)
"abc123"
iex> ctx = %Axn.Context{}
iex> Axn.Context.get_private(ctx, :non_existent)
nil
Gets a value from the private storage of the context with a default.
Examples
iex> ctx = %Axn.Context{private: %{correlation_id: "abc123"}}
iex> Axn.Context.get_private(ctx, :correlation_id, "default")
"abc123"
iex> ctx = %Axn.Context{}
iex> Axn.Context.get_private(ctx, :non_existent, "my_default")
"my_default"
Updates the params in the context.
Examples
iex> ctx = %Axn.Context{}
iex> updated_ctx = Axn.Context.put_params(ctx, %{name: "John", age: 25})
iex> updated_ctx.params
%{name: "John", age: 25}
Puts a value in the private storage of the context.
Examples
iex> ctx = %Axn.Context{}
iex> updated_ctx = Axn.Context.put_private(ctx, :correlation_id, "abc123")
iex> updated_ctx.private
%{correlation_id: "abc123"}
Updates the result in the context.
Examples
iex> ctx = %Axn.Context{}
iex> updated_ctx = Axn.Context.put_result(ctx, {:ok, %{id: 123}})
iex> updated_ctx.result
{:ok, %{id: 123}}