Class: DispatchRider::Callbacks::Storage

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

Overview

Storage for callbacks.

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 = Hash.new { |storage, key| storage[key] = [] }
end

Instance Method Details

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

Parameters:

  • event (Symbol)

    name of the event

  • block_param (#call) (defaults to: nil)

    block passed as a parameter

  • &block (Proc)


22
23
24
25
26
27
28
29
30
# File 'lib/dispatch-rider/callbacks/storage.rb', line 22

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

Parameters:

  • event (Symbol)

    name of the event

  • block_param (#call) (defaults to: nil)

    block passed as a parameter

  • &block (Proc)


35
36
37
# File 'lib/dispatch-rider/callbacks/storage.rb', line 35

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

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

Parameters:

  • event (Symbol)

    name of the event

  • block_param (#call) (defaults to: nil)

    block passed as a parameter

  • &block (Proc)


12
13
14
15
16
17
# File 'lib/dispatch-rider/callbacks/storage.rb', line 12

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

#for(event) ⇒ Object

Parameters:

  • event (Symbol)

    name of the event



40
41
42
# File 'lib/dispatch-rider/callbacks/storage.rb', line 40

def for(event)
  @callbacks[event]
end