module

Lustra::Model::HasHooks::ClassMethods

Instance methods

after(event_name : Symbol, &block : Lustra::Model -> Nil)

Register a callback to be executed AFTER the specified lifecycle event

event_name - the lifecycle event (:create, :update, :validate, etc.) block - the callback block to execute

Note: The block parameter has type Lustra::Model. Use .as(YourModel) to access model-specific methods and columns.

Example:

after(:create) do |model|
  user = model.as(User)
  user.send_welcome_email
end
Source
before(event_name : Symbol, &block : Lustra::Model -> Nil)

Register a callback to be executed BEFORE the specified lifecycle event

event_name - the lifecycle event (:create, :update, :validate, etc.) block - the callback block to execute

Note: The block parameter has type Lustra::Model. Use .as(YourModel) to access model-specific methods and columns.

Example:

before(:validate) do |model|
  user = model.as(User)
  user.email = user.email.downcase
end
Source