View Source Ash.Resource.Calculation behaviour (ash v3.0.11)

The behaviour for defining a module calculation, and the struct for storing a defined calculation.

Summary

Types

@type opts() :: Keyword.t()
@type ref() :: {module(), Keyword.t()} | module()
@type t() :: %Ash.Resource.Calculation{
  allow_nil?: boolean(),
  arguments: [Ash.Resource.Calculation.Argument.t()],
  calculation: module() | {module(), keyword()},
  constraints: keyword(),
  description: nil | String.t(),
  filterable?: boolean(),
  load: keyword(),
  name: atom(),
  public?: boolean(),
  sensitive?: term(),
  sortable?: boolean(),
  type: nil | Ash.Type.t()
}

Callbacks

Link to this callback

calculate(records, opts, context)

View Source (optional)
@callback calculate(
  records :: [Ash.Resource.record()],
  opts :: opts(),
  context :: Ash.Resource.Calculation.Context.t()
) :: {:ok, [term()]} | [term()] | {:error, term()} | :unknown
@callback describe(opts :: opts()) :: String.t()
Link to this callback

expression(opts, context)

View Source (optional)
@callback expression(opts :: opts(), context :: Ash.Resource.Calculation.Context.t()) ::
  any()
@callback has_expression?() :: boolean()
@callback init(opts :: opts()) :: {:ok, opts()} | {:error, term()}
Link to this callback

load(query, opts, context)

View Source
@callback load(
  query :: Ash.Query.t(),
  opts :: opts(),
  context :: Ash.Resource.Calculation.Context.t()
) ::
  atom() | [atom()] | Keyword.t()
@callback strict_loads?() :: boolean()

Functions