Class: Stone::Callbacks
- Inherits:
-
Hash
- Object
- Hash
- Stone::Callbacks
- Defined in:
- lib/stone/callbacks.rb
Constant Summary collapse
- CALLBACKS =
[ :before_save, :after_save, :before_create, :after_create, :before_destroy, :after_destroy ]
Instance Method Summary collapse
-
#fire(cb_sym, obj) ⇒ Object
- Sends any methods registered under
cb_sym
toobj
=== Parameterscb_sym
- Used to retrieve the methods to send
obj
-
The object to which the retrieved methods are sent.
- Used to retrieve the methods to send
- Sends any methods registered under
-
#register(cb_sym, meth, klass) ⇒ Object
- Adds a given
meth
to thecb_sym
array in the current Callbacks hash based onklass
=== Parameterscb_sym
- where
meth
will be addedmeth
- method to be added
klass
-
determines which
cb_sym
array will be used.
- method to be added
- where
- Adds a given
-
#register_klass(klass) ⇒ Object
- Registers the
klass
with the current instance of Callbacks in Resource === Parametersklass
-
The class to be registered.
- Registers the
Instance Method Details
#fire(cb_sym, obj) ⇒ Object
Sends any methods registered under cb_sym
to obj
Parameters
cb_sym
-
Used to retrieve the methods to send
obj
-
The object to which the retrieved methods are sent
41 42 43 44 45 46 47 48 |
# File 'lib/stone/callbacks.rb', line 41 def fire(cb_sym, obj) unless obj.class.to_s.make_key == :class self[obj.class.to_s.make_key][cb_sym].each do |meth| obj.send(meth) unless meth.blank? end end true end |
#register(cb_sym, meth, klass) ⇒ Object
Adds a given meth
to the cb_sym
array in the current Callbacks hash based on klass
Parameters
cb_sym
-
where
meth
will be added meth
-
method to be added
klass
-
determines which
cb_sym
array will be used
33 34 35 |
# File 'lib/stone/callbacks.rb', line 33 def register(cb_sym, meth, klass) self[klass.to_s.make_key][cb_sym] << meth end |
#register_klass(klass) ⇒ Object
Registers the klass
with the current instance of Callbacks in Resource
Parameters
klass
-
The class to be registered
20 21 22 23 24 25 |
# File 'lib/stone/callbacks.rb', line 20 def register_klass(klass) self[klass.to_s.make_key] = {} CALLBACKS.each do |cb_sym| self[klass.to_s.make_key][cb_sym] = [] end end |