module Lustra::Model::HasHooks::ClassMethods

Defined in:

lustra/model/modules/has_hooks.cr

Instance Method Summary

Instance Method Detail

def 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

[View source]
def 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

[View source]