module
Lustra::Model::HasHooks
Overview
This module provides the callback system for Lustra::Model
, allowing you to hook into
model lifecycle events like :create
, :update
, :validate
, etc.
Direct including types
Defined in:
lustra/model/modules/has_hooks.crMacro Summary
-
after(event_name, method_name)
Macro version of
after
- calls a method instead of a block -
before(event_name, method_name)
Macro version of
before
- calls a method instead of a block
Instance Method Summary
-
#trigger_after_events(event_name)
Triggers the events hooked after
event_name
-
#trigger_before_events(event_name)
Triggers the events hooked before
event_name
-
#with_triggers(event_name, &)
This performs theses operations:
Macro Detail
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.
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.
Instance Method Detail
This performs theses operations:
model.with_triggers("email_sent") do |m|
model.send_email
end
Returns self