class Synapses::Contract::Exchange

@author Alexander Semyonov <al@semyonov.us>

Attributes

channel[RW]

@return [AMQP::Channel]

name[RW]

@return [String]

options[RW]

@return [Hash]

type[RW]

@return ['direct', 'topic', 'fanout', 'headers']

Public Class Methods

new(name, options = {}) click to toggle source

@param [String] name @param [Hash] options see {AMQP::Exchange}

# File lib/synapses/contract/exchange.rb, line 17
def initialize(name, options = {})
  @name = name
  @type = options.delete('type') { raise "Type for exchange #{name} is not set" }
  @options = options || {}
end

Public Instance Methods

connect(channel) click to toggle source

@param [AMQP::Channel] channel @return [AMQP::Exchange]

# File lib/synapses/contract/exchange.rb, line 31
def connect(channel)
  @exchange = AMQP::Exchange.new(channel, type, name, options)
end
connected?() click to toggle source

@return [Boolean]

# File lib/synapses/contract/exchange.rb, line 36
def connected?
  !!@queue
end
exchange(channel=self.channel) click to toggle source

@param [AMQP::Channel] channel @return [AMQP::Exchange]

# File lib/synapses/contract/exchange.rb, line 42
def exchange(channel=self.channel)
  connect(channel) unless connected?
  @exchange
end