Ash.Subject (ash v3.5.32)
View SourceProvides a consistent API for common operations across Ash.Changeset
,
Ash.Query
, and Ash.ActionInput
. It allows you to write generic code that works
with any of these types without needing to pattern match or special-case your logic.
Summary
Functions
Adds an error or list of errors to the subject.
Adds a callback to be executed after the action.
Adds a callback to be executed before the action.
Deletes one or more arguments from the subject.
Fetches an argument value from the subject.
Gets an argument value from the subject.
Gets an argument or attribute value from a Changeset, or just an argument from other subjects.
Puts a key-value pair into the subject's context.
Sets a single argument on the subject.
Sets multiple arguments on the subject.
Sets the context for the subject.
Sets a private argument on the subject.
Sets multiple private arguments on the subject.
Types
@type t() :: Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t()
Functions
@spec add_error(t(), Ash.Error.error_input() | [Ash.Error.error_input()]) :: t()
Adds an error or list of errors to the subject.
Supports all subject types (Changeset, Query, ActionInput) and maintains type consistency.
Parameters
subject
- The subject to add errors toerrors
- Error or list of errors to add
Adds a callback to be executed after the action.
Note: Query only supports 2-arity callbacks and ignores opts.
Parameters
subject
- The subject to add callback tocallback
- Function that processes the resultopts
- Options including:prepend?
(ignored for Query)
Adds a callback to be executed before the action.
Parameters
subject
- The subject to add callback tocallback
- Function that takes and returns the subjectopts
- Options including:prepend?
to add at beginning
Deletes one or more arguments from the subject.
Parameters
subject
- The subject to delete arguments fromarguments
- Single argument name or list of argument names to delete
Fetches an argument value from the subject.
Returns {:ok, value}
if the argument exists, :error
otherwise.
Supports both atom and string argument names.
Parameters
subject
- The subject to fetch argument fromargument
- The argument name (atom or string)
Gets an argument value from the subject.
Supports both atom and string argument names.
Parameters
subject
- The subject to get argument fromargument
- The argument name (atom or string)
Gets an argument or attribute value from a Changeset, or just an argument from other subjects.
For Changesets, this can retrieve both arguments and attributes. For Query and ActionInput, this only retrieves arguments.
Parameters
subject
- The subject to get value fromname
- The argument or attribute name (atom or string)
Puts a key-value pair into the subject's context.
Parameters
subject
- The subject to update context onkey
- The context keyvalue
- The value to store
Sets a single argument on the subject.
Parameters
subject
- The subject to set argument onargument
- The argument name (atom or string)value
- The value to set
Sets multiple arguments on the subject.
Takes a map of argument names to values and sets them all.
Parameters
subject
- The subject to set arguments onarguments
- Map of argument names to values
Sets the context for the subject.
Merges the provided map into the subject's existing context. For Changeset and Query, delegates to their specific implementations.
Parameters
subject
- The subject to set context oncontext
- Map of context data to merge
@spec set_private_argument( Ash.Changeset.t() | Ash.ActionInput.t(), atom() | binary(), term() ) :: Ash.Changeset.t() | Ash.ActionInput.t()
Sets a private argument on the subject.
Private arguments are not exposed in the public API. Only supported by Changeset and ActionInput.
Parameters
subject
- The subject to set private argument on (Changeset or ActionInput)argument
- The argument name (atom or string)value
- The value to set
@spec set_private_arguments(Ash.Changeset.t() | Ash.ActionInput.t(), map()) :: Ash.Changeset.t() | Ash.ActionInput.t()
Sets multiple private arguments on the subject.
Takes a map of argument names to values and sets them all as private arguments. Only supported by Changeset and ActionInput.
Parameters
subject
- The subject to set private arguments on (Changeset or ActionInput)arguments
- Map of argument names to values