class Clear::Model::EventManager
- Clear::Model::EventManager
- Reference
- Object
Overview
Global storage for model lifecycle event management
This class acts as a storage and can trigger events This class a singleton.
Defined in:
clear/model/event_manager.crConstant Summary
-
EVENT_CALLBACKS =
{} of EventKey => Array(HookFunction)
-
INHERITANCE_MAP =
{} of String => String
Class Method Summary
-
.add_inheritance(parent, child)
Map the inheritance between models.
-
.attach(klazz, direction : Symbol, event : Symbol, block : HookFunction)
Add an event for a specific class, to a specific direction (after or before), a specific event Symbol (validate, save, commit...)
- .has_trigger?(klazz, direction : Symbol, event : Symbol)
-
.trigger(klazz, direction : Symbol, event : Symbol, mdl : Clear::Model)
Trigger events callback for a specific model.
Class Method Detail
def self.add_inheritance(parent, child)
#
Map the inheritance between models. Events which belongs to parent model are triggered when child model lifecycle actions occurs
def self.attach(klazz, direction : Symbol, event : Symbol, block : HookFunction)
#
Add an event for a specific class, to a specific direction (after or before), a specific event Symbol (validate, save, commit...)
def self.trigger(klazz, direction : Symbol, event : Symbol, mdl : Clear::Model)
#
Trigger events callback for a specific model.
Direction can be :before
and :after
In case of :before
direction, the events are called in reverse order:
before:
- Last defined event
- First defined event
action
after:
- First defined events
- Last defined events