Class: DispatchRider::Callbacks::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch-rider/callbacks/storage.rb

Instance Method Summary collapse

Constructor Details

#initializeStorage

Returns a new instance of Storage.



5
6
7
# File 'lib/dispatch-rider/callbacks/storage.rb', line 5

def initialize
  @callbacks = {}
end

Instance Method Details

#after(event, block_param = nil, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/dispatch-rider/callbacks/storage.rb', line 16

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



26
27
28
29
# File 'lib/dispatch-rider/callbacks/storage.rb', line 26

def around(event, block_param = nil, &block)
  @callbacks[event] ||= []
  @callbacks[event] << (block_param || block)
end

#before(event, block_param = nil, &block) ⇒ Object



9
10
11
12
13
14
# File 'lib/dispatch-rider/callbacks/storage.rb', line 9

def before(event, block_param = nil, &block)
  around(event) do |job, *args|
    (block_param || block).call(*args)
    job.call
  end
end

#for(event) ⇒ Object



31
32
33
# File 'lib/dispatch-rider/callbacks/storage.rb', line 31

def for(event)
  @callbacks[event] || []
end