class Clear::Model::EventManager

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.cr

Constant Summary

EVENT_CALLBACKS = {} of EventKey => Array(HookFunction)
INHERITANCE_MAP = {} of String => String

Class Method Summary

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


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


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

[View source]