Class: Bunny::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/stuffed_bunny/bunny_overrides.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name, options = {}) ⇒ Exchange

Returns a new instance of Exchange.



40
41
42
43
# File 'lib/stuffed_bunny/bunny_overrides.rb', line 40

def initialize(client, name, options = {})
  @client, @name  = client, name
  @type = options[:type]
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



38
39
40
# File 'lib/stuffed_bunny/bunny_overrides.rb', line 38

def client
  @client
end

#nameObject

Returns the value of attribute name.



38
39
40
# File 'lib/stuffed_bunny/bunny_overrides.rb', line 38

def name
  @name
end

#typeObject

Returns the value of attribute type.



38
39
40
# File 'lib/stuffed_bunny/bunny_overrides.rb', line 38

def type
  @type
end

Instance Method Details

#publish(data, options = {}) ⇒ Object

To facilite testing this adds a Struct containing the data message and routing key to the routed_messages.

Example usage: Bunny.run do |b|

topic = b.exchange("some_topic_name", SOME_EXCHANGE_OPTIONS)
options = { :key => "some.routing.key" }.merge(SOME_PUBLISH_OPTIONS)
topic.publish("some message", options)

end

Testing: … routed_message = @bunny.exchanges.routed_messages assert_equal “some message”, routed_message.message assert_equal “some.routing.key”, routed_message.key



64
65
66
# File 'lib/stuffed_bunny/bunny_overrides.rb', line 64

def publish(data, options = {})
  routed_messages << Struct.new(:message, :key).new(data, options[:key])
end

#routed_messagesObject



45
46
47
# File 'lib/stuffed_bunny/bunny_overrides.rb', line 45

def routed_messages
  @routed_messaged ||= []
end