Class: Moqueue::MockExchange
- Inherits:
-
Object
- Object
- Moqueue::MockExchange
- Defined in:
- lib/moqueue/mock_exchange.rb
Defined Under Namespace
Classes: BindingKey
Instance Attribute Summary collapse
-
#fanout ⇒ Object
readonly
Returns the value of attribute fanout.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
- #acked_messages ⇒ Object
- #attach_queue(queue, opts = {}) ⇒ Object
- #attached_queues ⇒ Object
-
#initialize(opts = {}) ⇒ MockExchange
constructor
A new instance of MockExchange.
- #publish(message, opts = {}) ⇒ Object
- #received_ack_for_message?(message) ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ MockExchange
Returns a new instance of MockExchange.
22 23 24 25 26 27 28 |
# File 'lib/moqueue/mock_exchange.rb', line 22 def initialize(opts={}) if @topic = opts[:topic] MockBroker.instance.register_topic_exchange(self) elsif @fanout = opts[:fanout] MockBroker.instance.register_fanout_exchange(self) end end |
Instance Attribute Details
#fanout ⇒ Object (readonly)
Returns the value of attribute fanout.
4 5 6 |
# File 'lib/moqueue/mock_exchange.rb', line 4 def fanout @fanout end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
4 5 6 |
# File 'lib/moqueue/mock_exchange.rb', line 4 def topic @topic end |
Class Method Details
.new(opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/moqueue/mock_exchange.rb', line 8 def new(opts={}) if opts[:topic] && topic_exchange = MockBroker.instance.find_topic_exchange(opts[:topic]) return topic_exchange end if opts[:fanout] && fanout = MockBroker.instance.find_fanout_exchange(opts[:fanout]) return fanout end super end |
Instance Method Details
#acked_messages ⇒ Object
34 35 36 |
# File 'lib/moqueue/mock_exchange.rb', line 34 def ||= [] end |
#attach_queue(queue, opts = {}) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/moqueue/mock_exchange.rb', line 38 def attach_queue(queue, opts={}) if topic attached_queues << [queue, BindingKey.new(opts[:key])] else attached_queues << queue end end |
#attached_queues ⇒ Object
30 31 32 |
# File 'lib/moqueue/mock_exchange.rb', line 30 def attached_queues @attached_queues ||= [] end |
#publish(message, opts = {}) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/moqueue/mock_exchange.rb', line 46 def publish(, opts={}) require_routing_key(opts) if topic matching_queues(opts).each do |q| (q.receive(, prepare_header_opts(opts))) end end |
#received_ack_for_message?(message) ⇒ Boolean
53 54 55 |
# File 'lib/moqueue/mock_exchange.rb', line 53 def () .include?() end |