EctoHooks behaviour (ecto_hooks v1.0.2) View Source
Module exposing various utility functions for interacting with, and introspecting the state of EctoHooks.
For more extensive usage instructions, please see associated documentation for
EctoHooks.Repo
.
Link to this section Summary
Functions
Alternative interface for initializing EctoHooks when use
-ed in a module as follows
Disables the next before_*
or after_*
hook from executing.
Enables the next before_*
or after_*
hook to execute from within the context of
an already running hook.
Returns a boolean indicating if any before_*
or after_*
hooks are allowed
to execute in the current process.
Utility function which returns the "nesting" of the current EctoHooks context.
Utility function which returns true if currently executing inside the context of an Ecto Hook.
Link to this section Functions
Alternative interface for initializing EctoHooks when use
-ed in a module as follows:
def MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
use EctoHooks
end
Please see EctoHooks.Repo
for more information about EctoHooks usage, examples,
and considerations.
Specs
disable_hooks() :: :ok
Disables the next before_*
or after_*
hook from executing.
This is automatically cleared after triggering any Ecto.Repo
callback.
Specs
enable_hooks() :: :ok
Enables the next before_*
or after_*
hook to execute from within the context of
an already running hook.
As a mitigation for infinitely looping hooks caused by hooks triggering other hooks, hooks will not run while inside the stacktrace of another hook.
Calling this function opts out of this mitigation for the next hook being executed.
Specs
hooks_enabled?() :: boolean()
Returns a boolean indicating if any before_*
or after_*
hooks are allowed
to execute in the current process.
Note that calls to Ecto.Repo
callbacks may reset or change the state of this flag,
and that this function is primarily exposed for introspection or debugging purposes.
Specs
hooks_ref_count() :: pos_integer()
Utility function which returns the "nesting" of the current EctoHooks context.
By default, every hook will "acquire" an EctoHook context and increment a ref count. These ref counts are automatically decremented once a hook finishes running.
This is provided as a lower level alternative the enable_hooks/0
, disable_hooks/0
,
and hooks_enabled?/0
functions.
Specs
in_hook?() :: boolean()
Utility function which returns true if currently executing inside the context of an Ecto Hook.
Link to this section Callbacks
Specs
after_delete(schema_struct :: struct(), delta :: EctoHooks.Delta.t()) :: struct()
Specs
after_get(schema_struct :: struct(), delta :: EctoHooks.Delta.t()) :: struct()
Specs
after_insert(schema_struct :: struct(), delta :: EctoHooks.Delta.t()) :: struct()
Specs
after_update(schema_struct :: struct(), delta :: EctoHooks.Delta.t()) :: struct()
Specs
before_delete(queryable :: %Ecto.Queryable{}) :: %Ecto.Queryable{}
Specs
before_insert(queryable :: %Ecto.Queryable{}) :: %Ecto.Queryable{}
Specs
before_update(queryable :: %Ecto.Queryable{}) :: %Ecto.Queryable{}