Sha256: 8bc8cc2f10e8594833d0ab3c7031b2ced8250afbe8688819115c4120caf248d8

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

module AMQ
  module Client
    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)
        callbacks = Array(self.callbacks[name])
        callbacks.map { |c| c.call(*args, &block) } if callbacks.any?
      end

      def exec_callback_once(name, *args, &block)
        callbacks = Array(self.callbacks.delete(name))
        callbacks.map { |c| c.call(*args, &block) } if callbacks.any?
      end

      def exec_callback_yielding_self(name, *args, &block)
        callbacks = Array(self.callbacks[name])
        callbacks.map { |c| c.call(self, *args, &block) } if callbacks.any?
      end

      def exec_callback_once_yielding_self(name, *args, &block)
        callbacks = Array(self.callbacks.delete(name))
        callbacks.map { |c| c.call(self, *args, &block) } if callbacks.any?
      end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
amq-client-0.7.0.alpha25 lib/amq/client/callbacks.rb
amq-client-0.7.0.alpha24 lib/amq/client/callbacks.rb