Sha256: 8c5f0e791671cc7c4dd737366cceedf74b18b19e569d061dec27989bd866f05b
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
module DispatchRider module Callbacks # Storage for callbacks. class Storage def initialize @callbacks = Hash.new { |storage, key| storage[key] = [] } end # @param [Symbol] event name of the event # @param [#call] block_param block passed as a parameter # @param [Proc] &block def before(event, block_param = nil, &block) around(event) do |job, *args| (block_param || block).call(*args) job.call end end # @param [Symbol] event name of the event # @param [#call] block_param block passed as a parameter # @param [Proc] &block def after(event, block_param = nil, &block) around(event) do |job, *args| begin job.call ensure (block_param || block).call(*args) end end end # @param [Symbol] event name of the event # @param [#call] block_param block passed as a parameter # @param [Proc] &block def around(event, block_param = nil, &block) @callbacks[event] << (block_param || block) end # @param [Symbol] event name of the event def for(event) @callbacks[event] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dispatch-rider-2.1.0 | lib/dispatch-rider/callbacks/storage.rb |
dispatch-rider-2.0.0 | lib/dispatch-rider/callbacks/storage.rb |