class DispatchRider::Callbacks::Storage

Storage for callbacks.

Public Class Methods

new() click to toggle source
# File lib/dispatch-rider/callbacks/storage.rb, line 6
def initialize
  @callbacks = Hash.new { |storage, key| storage[key] = [] }
end

Public Instance Methods

after(event, block_param = nil, &block) click to toggle source

@param [Symbol] event name of the event @param [#call] block_param block passed as a parameter @param [Proc] &block

# 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) click to toggle source

@param [Symbol] event name of the event @param [#call] block_param block passed as a parameter @param [Proc] &block

# 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) click to toggle source

@param [Symbol] event name of the event @param [#call] block_param block passed as a parameter @param [Proc] &block

# 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) click to toggle source

@param [Symbol] event name of the event

# File lib/dispatch-rider/callbacks/storage.rb, line 41
def for(event)
  @callbacks[event]
end