Sha256: 0be186edb079979dc02e8d652a3eaf59ee6ee5db80642b6faaa338323ff16bf6

Contents?: true

Size: 1.56 KB

Versions: 24

Compression:

Stored size: 1.56 KB

Contents

module AMQP
  module Callbacks

    def redefine_callback(event, callable = nil, &block)
      f = (callable || block)
      # yes, re-assign!
      @callbacks[event] = [f]

      self
    end

    def define_callback(event, callable = nil, &block)
      f = (callable || block)

      @callbacks[event] ||= []
      @callbacks[event] << f if f

      self
    end # define_callback(event, &block)
    alias append_callback define_callback

    def prepend_callback(event, &block)
      @callbacks[event] ||= []
      @callbacks[event].unshift(block)

      self
    end # prepend_callback(event, &block)

    def clear_callbacks(event)
      @callbacks[event].clear if @callbacks[event]
    end # clear_callbacks(event)


    def exec_callback(name, *args, &block)
      list = Array(@callbacks[name])
      if list.any?
        list.each { |c| c.call(*args, &block) }
      end
    end

    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

    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

    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

    def has_callback?(name)
      @callbacks[name] && !@callbacks[name].empty?
    end # has_callback?
  end # Callbacks
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
amqp-1.8.0 lib/amqp/callbacks.rb
amqp-1.7.0 lib/amqp/callbacks.rb
amqp-1.6.0 lib/amqp/callbacks.rb
amqp-1.5.3 lib/amqp/callbacks.rb
amqp-1.5.2 lib/amqp/callbacks.rb
amqp-1.5.1 lib/amqp/callbacks.rb
amqp-1.5.0 lib/amqp/callbacks.rb
amqp-1.4.2 lib/amqp/callbacks.rb
amqp-1.4.1 lib/amqp/callbacks.rb
amqp-1.4.0 lib/amqp/callbacks.rb
amqp-1.3.0 lib/amqp/callbacks.rb
amqp-1.2.1 lib/amqp/callbacks.rb
amqp-1.2.0 lib/amqp/callbacks.rb
amqp-1.1.8 lib/amqp/callbacks.rb
amqp-1.1.7 lib/amqp/callbacks.rb
amqp-1.1.6 lib/amqp/callbacks.rb
amqp-1.1.5 lib/amqp/callbacks.rb
amqp-1.1.4 lib/amqp/callbacks.rb
amqp-1.1.3 lib/amqp/callbacks.rb
amqp-1.1.2 lib/amqp/callbacks.rb