Lustra::Model::EventManager
This class manages the storage and execution of model lifecycle callbacks. It acts as a singleton that stores callbacks for all models and triggers them during appropriate lifecycle events.
Key concepts:
EVENT_CALLBACKS: Hash storing all registered callbacks by{class_name, direction, event}- Direction:
:beforeor:after - Events:
:create,:update,:validate,:save, etc.
Usage: This is used internally by Lustra::Model::HasHooks
Global storage for model lifecycle event management
Constants
Class methods
Map the inheritance between models. Events which belongs to parent model are triggered when child model lifecycle actions occurs
Register a callback for a specific model class, direction, and event
klass - The model class
direction - :before or :after
event - The lifecycle event (:create, :update, :validate, etc.)
block - The callback function to execute
This is called internally by Lustra::Model::HasHooks when you define
before or after callbacks in your model.
Trigger all callbacks for a specific model, direction, and event
klass - the model class
direction - :before or :after
event - the lifecycle event (:create, :update, :validate, etc.)
mdl - the model instance
Callback execution order:
:beforecallbacks: Last defined -> First defined (reverse order):aftercallbacks: First defined -> Last defined (normal order)
This ensures that the most recently defined callbacks run first for :before
and last for :after, allowing for proper layering of functionality.