Sha256: 49650c2403d0bbcdda33d4baec8664f32b6fe4ecaca25c23008a9b5a723c46d2

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'synapses/contract'
require 'synapses/contract/connectible'

module Synapses
  class Contract
    # @author Alexander Semyonov <al@semyonov.us>
    class Exchange
      # @return [String]
      attr_accessor :name
      # @return ['direct', 'topic', 'fanout', 'headers']
      attr_accessor :type
      # @return [Hash]
      attr_accessor :options

      # @param [String] name
      # @param [Hash] options see {AMQP::Exchange}
      def initialize(name, options = {})
        @name = name
        @type = options.delete('type') { raise "Type for exchange #{name} is not set" }
        @options = options || {}
      end

      # @return [AMQP::Channel]
      attr_accessor :channel
      def channel
        @channel ||= Synapses.default_channel
      end

      # @param [AMQP::Channel] channel
      # @return [AMQP::Exchange]
      def connect(channel)
        @exchange = AMQP::Exchange.new(channel, type, name, options)
      end

      # @return [Boolean]
      def connected?
        !!@queue
      end

      # @param [AMQP::Channel] channel
      # @return [AMQP::Exchange]
      def exchange(channel=self.channel)
        connect(channel) unless connected?
        @exchange
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
synapses-0.0.1 lib/synapses/contract/exchange.rb