Sha256: e943ccc59d0fb7ea78e5c0c06354769ea7c5be8328810608c312269bb4d4bc79

Contents?: true

Size: 1.71 KB

Versions: 24

Compression:

Stored size: 1.71 KB

Contents

require "amqp/openable"
require "amqp/callbacks"

module AMQP
  module RegisterEntityMixin
    # @example Registering Channel implementation
    #  Adapter.register_entity(:channel, Channel)
    #   # ... so then I can do:
    #  channel = client.channel(1)
    #  # instead of:
    #  channel = Channel.new(client, 1)
    def register_entity(name, klass)
      define_method(name) do |*args, &block|
        klass.new(self, *args, &block)
      end # define_method
    end # register_entity
  end # RegisterEntityMixin

  module ProtocolMethodHandlers
    def handle(klass, &block)
      HandlersRegistry.register(klass, &block)
    end

    def handlers
      HandlersRegistry.handlers
    end
  end # ProtocolMethodHandlers


  # AMQ entities, as implemented by AMQP, have callbacks and can run them
  # when necessary.
  #
  # @note Exchanges and queues implementation is based on this class.
  #
  # @abstract
  module Entity

    #
    # Behaviors
    #

    include Openable
    include Callbacks

    #
    # API
    #

    # @return [Array<#call>]
    attr_reader :callbacks


    def initialize(connection)
      @connection = connection
      # Be careful with default values for #ruby hashes: h = Hash.new(Array.new); h[:key] ||= 1
      # won't assign anything to :key. MK.
      @callbacks  = Hash.new
    end # initialize
  end # Entity

  # Common behavior of AMQ entities that can be either client or server-named, for example, exchanges and queues.
  module ServerNamedEntity

    # @return [Boolean] true if this entity is anonymous (server-named)
    def server_named?
      @server_named || @name.nil? || @name.empty?
    end
    # backwards compabitility. MK.
    alias anonymous? server_named?
  end # ServerNamedEntity
end

Version data entries

24 entries across 24 versions & 1 rubygems

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