View Source ExTeal.Resource.Attributes behaviour (ExTeal v0.27.9)

Provides the permitted_attributes/3 callback used for filtering attributes.

This behaviour is used by the following ExTeal.Resource actions:

  • ExTeal.Resource.Delete
  • ExTeal.Resource.Create

Summary

Callbacks

Used to determine which attributes are permitted during create and update.

Callbacks

Link to this callback

permitted_attributes(t, attributes, arg3)

View Source
@callback permitted_attributes(
  Plug.Conn.t(),
  ExTeal.Resource.attributes(),
  :update | :create
) ::
  ExTeal.Resource.attributes()

Used to determine which attributes are permitted during create and update.

The attributes map (the second argument) is a "flattened" version including the values at data/attributes, data/type and any relationship values in data/relationships/[name]/data/id as name_id.

The third argument is the atom of the action being called.

Example:

defmodule MyApp.V1.PostResource do
  use ExTeal.Resource

  def permitted_attributes(conn, attrs, :create) do
    attrs
    |> Map.take(~w(title body type category_id))
    |> Map.merge("author_id", conn.assigns[:current_user])
  end

  def permitted_attributes(_conn, attrs, :update) do
    Map.take(attrs, ~w(title body type category_id))
  end
end

Functions

Link to this function

clean_and_nest_params(attrs)

View Source
Link to this function

combine_and_key_by_field_attr(fields)

View Source
Link to this function

maybe_sanitize(attrs, fields, arg3)

View Source
@spec maybe_sanitize(map(), map(), boolean()) :: map()
Link to this function

sanitize_as(field, sanitizer)

View Source
Link to this function

sanitize_param(arg, fields)

View Source