Sha256: 2cef1b064893ad2b4dc58bd31785248b81ff18c56bd7d4bb36fa5f7d44149c1a

Contents?: true

Size: 1.84 KB

Versions: 32

Compression:

Stored size: 1.84 KB

Contents

# encoding: utf-8

module AMQ
  module Client
    module Async
      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 # Async
  end # Client
end # AMQ

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
amq-client-1.0.4 lib/amq/client/async/callbacks.rb
amq-client-1.0.3 lib/amq/client/async/callbacks.rb
amq-client-1.1.0.pre1 lib/amq/client/async/callbacks.rb
amq-client-1.0.2 lib/amq/client/async/callbacks.rb
amq-client-1.0.1 lib/amq/client/async/callbacks.rb
amq-client-1.0.0 lib/amq/client/async/callbacks.rb
amq-client-0.9.12 lib/amq/client/async/callbacks.rb
amq-client-0.9.11 lib/amq/client/async/callbacks.rb
amq-client-0.9.10 lib/amq/client/async/callbacks.rb
amq-client-0.9.9 lib/amq/client/async/callbacks.rb
amq-client-0.9.8 lib/amq/client/async/callbacks.rb
amq-client-0.9.7 lib/amq/client/async/callbacks.rb
amq-client-0.9.6 lib/amq/client/async/callbacks.rb
amq-client-0.9.5 lib/amq/client/async/callbacks.rb
amq-client-0.9.4 lib/amq/client/async/callbacks.rb
amq-client-1.0.0.pre2 lib/amq/client/async/callbacks.rb
amq-client-0.9.3 lib/amq/client/async/callbacks.rb
amq-client-1.0.0.pre1 lib/amq/client/async/callbacks.rb
amq-client-0.9.2 lib/amq/client/async/callbacks.rb
amq-client-0.9.1 lib/amq/client/async/callbacks.rb