Module: AMQP::Callbacks
Instance Method Summary collapse
-
#clear_callbacks(event) ⇒ Object
prepend_callback(event, &block).
- #define_callback(event, callable = nil, &block) ⇒ Object (also: #append_callback)
- #exec_callback(name, *args, &block) ⇒ Object
- #exec_callback_once(name, *args, &block) ⇒ Object
- #exec_callback_once_yielding_self(name, *args, &block) ⇒ Object
- #exec_callback_yielding_self(name, *args, &block) ⇒ Object
- #has_callback?(name) ⇒ Boolean
- #prepend_callback(event, &block) ⇒ Object
- #redefine_callback(event, callable = nil, &block) ⇒ Object
Instance Method Details
#clear_callbacks(event) ⇒ Object
prepend_callback(event, &block)
29 30 31 |
# File 'lib/amqp/callbacks.rb', line 29 def clear_callbacks(event) @callbacks[event].clear if @callbacks[event] end |
#define_callback(event, callable = nil, &block) ⇒ Object Also known as: append_callback
12 13 14 15 16 17 18 19 |
# File 'lib/amqp/callbacks.rb', line 12 def define_callback(event, callable = nil, &block) f = (callable || block) @callbacks[event] ||= [] @callbacks[event] << f if f self end |
#exec_callback(name, *args, &block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/amqp/callbacks.rb', line 34 def exec_callback(name, *args, &block) list = Array(@callbacks[name]) if list.any? list.each { |c| c.call(*args, &block) } end end |
#exec_callback_once(name, *args, &block) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/amqp/callbacks.rb', line 41 def exec_callback_once(name, *args, &block) list = (@callbacks.delete(name) || Array.new) if list.any? list.each { |c| c.call(*args, &block) } end end |
#exec_callback_once_yielding_self(name, *args, &block) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/amqp/callbacks.rb', line 55 def exec_callback_once_yielding_self(name, *args, &block) list = (@callbacks.delete(name) || Array.new) if list.any? list.each { |c| c.call(self, *args, &block) } end end |
#exec_callback_yielding_self(name, *args, &block) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/amqp/callbacks.rb', line 48 def exec_callback_yielding_self(name, *args, &block) list = Array(@callbacks[name]) if list.any? list.each { |c| c.call(self, *args, &block) } end end |
#has_callback?(name) ⇒ Boolean
63 64 65 |
# File 'lib/amqp/callbacks.rb', line 63 def has_callback?(name) @callbacks[name] && !@callbacks[name].empty? end |
#prepend_callback(event, &block) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/amqp/callbacks.rb', line 22 def prepend_callback(event, &block) @callbacks[event] ||= [] @callbacks[event].unshift(block) self end |
#redefine_callback(event, callable = nil, &block) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/amqp/callbacks.rb', line 4 def redefine_callback(event, callable = nil, &block) f = (callable || block) # yes, re-assign! @callbacks[event] = [f] self end |