Sha256: a4c847473d79175586a5758f03733f413153243572e3177a006a5db312859d41

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'synapses/contract'
require 'synapses/contract/connectible'
require 'amqp/queue'

module Synapses
  class Contract
    # @author Alexander Semyonov <al@semyonov.us>
    class Queue
      # @return [String]
      attr_accessor :name

      # @return [Hash] see {AMQP::Queue#initialize}
      attr_accessor :options

      # @param [String] name
      # @param [Hash] options see {AMQP::Queue#initialize}
      def initialize(name, options = {})
        @name = name
        @bind = options.delete('bind') { raise "Exchange :bind is not specified for queue #{name}" }
        @options = options || {}
      end

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

      # @return [AMQP::Queue]
      def connect(channel=self.channel)
        @queue = AMQP::Queue.new(channel, name, options)
      end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

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