Sha256: af5f206a24abeca6d15388793654612ab5087a3e1f7818a5e1f68636403ee208
Contents?: true
Size: 1.22 KB
Versions: 18
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
18 entries across 18 versions & 1 rubygems