Class: DispatchRider::Callbacks::Storage
- Inherits:
-
Object
- Object
- DispatchRider::Callbacks::Storage
- Defined in:
- lib/dispatch-rider/callbacks/storage.rb
Overview
Storage for callbacks.
Instance Method Summary collapse
- #after(event, block_param = nil, &block) ⇒ Object
- #around(event, block_param = nil, &block) ⇒ Object
- #before(event, block_param = nil, &block) ⇒ Object
- #for(event) ⇒ Object
-
#initialize ⇒ Storage
constructor
A new instance of Storage.
Constructor Details
#initialize ⇒ Storage
Returns a new instance of Storage.
6 7 8 |
# File 'lib/dispatch-rider/callbacks/storage.rb', line 6 def initialize @callbacks = Hash.new { |storage, key| storage[key] = [] } end |
Instance Method Details
#after(event, block_param = nil, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/dispatch-rider/callbacks/storage.rb', line 23 def after(event, block_param = nil, &block) around(event) do |job, *args| begin job.call ensure (block_param || block).call(*args) end end end |
#around(event, block_param = nil, &block) ⇒ Object
36 37 38 |
# File 'lib/dispatch-rider/callbacks/storage.rb', line 36 def around(event, block_param = nil, &block) @callbacks[event] << (block_param || block) end |
#before(event, block_param = nil, &block) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/dispatch-rider/callbacks/storage.rb', line 13 def before(event, block_param = nil, &block) around(event) do |job, *args| (block_param || block).call(*args) job.call end end |
#for(event) ⇒ Object
41 42 43 |
# File 'lib/dispatch-rider/callbacks/storage.rb', line 41 def for(event) @callbacks[event] end |