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
with_triggers(event_name, &)
This performs theses operations:
- Call triggers
beforethe event - Yield the given block
- Call triggers
afterthe event
model.with_triggers("email_sent") do |m|
model.send_email
end
Returns self
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.
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.