Class: Lotus::Utils::Callbacks::Chain
- Inherits:
-
Array
- Object
- Array
- Lotus::Utils::Callbacks::Chain
- Defined in:
- lib/lotus/utils/callbacks.rb
Overview
Series of callbacks to be executed
Instance Method Summary collapse
-
#add(*callbacks, &blk) ⇒ void
Adds the given callbacks to the chain.
-
#run(context, *args) ⇒ Object
Runs all the callbacks in the chain.
Instance Method Details
#add(*callbacks, &blk) ⇒ void
This method returns an undefined value.
Adds the given callbacks to the chain
40 41 42 43 44 45 46 47 |
# File 'lib/lotus/utils/callbacks.rb', line 40 def add(*callbacks, &blk) callbacks.push blk if block_given? callbacks.each do |c| push Factory.fabricate(c) end uniq! end |
#run(context, *args) ⇒ Object
Runs all the callbacks in the chain. The only two ways to stop the execution are: ‘raise` or `throw`.
94 95 96 97 98 |
# File 'lib/lotus/utils/callbacks.rb', line 94 def run(context, *args) each do |callback| callback.call(context, *args) end end |