module

Lustra::Model::HasHooks

This module provides the callback system for Lustra::Model, allowing you to hook into model lifecycle events like :create, :update, :validate, etc.

Instance methods

trigger_after_events(event_name)

Triggers the events hooked after event_name

Source
trigger_before_events(event_name)

Triggers the events hooked before event_name

Source
with_triggers(event_name, &)

This performs theses operations:

  • Call triggers before the event
  • Yield the given block
  • Call triggers after the event
model.with_triggers("email_sent") do |m|
  model.send_email
end

Returns self

Source

Macros

after(event_name, method_name)

Macro version of after - calls a method instead of a block

Example: after(:create, :send_welcome_email) Equivalent to: after(:create) { |model| model.as(User).send_welcome_email }

The macro automatically casts to the correct type for you.

Source
before(event_name, method_name)

Macro version of before - calls a method instead of a block

Example: before(:validate, :sanitize_data) Equivalent to: before(:validate) { |model| model.as(User).sanitize_data }

The macro automatically casts to the correct type for you.

Source

Nested types