View Source Ash.PlugHelpers (ash v2.4.12)
Helpers for working with the Plug connection.
Link to this section Summary
Functions
Retrieves the actor from the Plug connection.
Retrieves the tenant from the Plug connection.
Sets the actor inside the Plug connection.
Sets the tenant inside the Plug connection.
Link to this section Functions
@spec get_actor(Plug.Conn.t()) :: nil | Ash.Resource.record()
Retrieves the actor from the Plug connection.
The actor is stored inside the connection's private fields.
deprecation-warning
Deprecation warning
This function checks to see if the actor is already set in the @actor
assign, and if so will emit a deprecation warning.
This is to allow apps using the previous method a chance to update.
Rather than setting the actor in the assigns, please use the set_actor/2
method.
example
Example
iex> actor = build_actor(%{email: "marty@1985.retro"})
...> conn = build_conn() |> put_private(:ash, %{actor: actor})
...> actor = get_actor(conn)
%{email: "marty@1985.retro"} = actor
iex> actor = build_actor(%{email: "marty@1985.retro"})
...> conn = build_conn() |> assign(:actor, actor)
...> actor = get_actor(conn)
%{email: "marty@1985.retro"} = actor
@spec get_tenant(Plug.Conn.t()) :: nil | Ash.Resource.record()
Retrieves the tenant from the Plug connection.
The tenant is stored inside the connection's private fields.
deprecation-warning
Deprecation warning
This function checks to see if the tenant is already set in the @tenant
assign, and if so will emit a deprecation warning.
This is to allow apps using the previous method a chance to update.
Rather than setting the tenant in the assigns, please use the set_tenant/2
method.
example
Example
iex> tenant = build_tenant(%{name: "Deliver-yesterday"})
...> conn = build_conn() |> put_private(:ash, %{tenant: tenant})
...> tenant = get_tenant(conn)
%{name: "Deliver-yesterday"} = tenant
iex> tenant = build_tenant(%{name: "Deliver-yesterday"})
...> conn = build_conn() |> assign(:tenant, tenant)
...> tenant = get_tenant(conn)
%{name: "Deliver-yesterday"} = tenant
@spec set_actor(Plug.Conn.t(), Ash.Resource.record()) :: Plug.Conn.t()
Sets the actor inside the Plug connection.
The actor is stored inside the connection's private fields.
example
Example
iex> actor = build_actor(%{email: "marty@1985.retro"})
...> conn = build_conn() |> set_actor(actor)
%Plug.Conn{private: %{ash: %{actor: %{email: "marty@1985.retro"}}}} = conn
@spec set_tenant(Plug.Conn.t(), Ash.Resource.record()) :: Plug.Conn.t()
Sets the tenant inside the Plug connection.
The tenant is stored inside the connection's private fields.
example
Example
iex> tenant = build_tenant(%{name: "Deliver-yesterday"})
...> conn = build_conn() |> set_tenant(tenant)
%Plug.Conn{private: %{ash: %{tenant: %{name: "Deliver-yesterday"}}}} = conn