#
View Source Ash.PlugHelpers (ash v2.4.22)

Helpers for working with the Plug connection.

# Link to this section Summary

## Functions

get_actor(arg1)

Retrieves the actor from the Plug connection.

get_tenant(arg1)

Retrieves the tenant from the Plug connection.

set_actor(conn, actor)

Sets the actor inside the Plug connection.

set_tenant(conn, tenant)

Sets the tenant inside the Plug connection.

# Link to this section Functions

Link to this function

# get_actor(arg1)

View Source

    @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

Link to this function

# get_tenant(arg1)

View Source

    @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

Link to this function

# set_actor(conn, actor)

View Source

    @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

Link to this function

# set_tenant(conn, tenant)

View Source

    @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