Parent

Files

Moqueue::MockExchange

Attributes

topic[R]
fanout[R]
direct[R]

Public Class Methods

new(opts={}) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 8
 8:       def new(opts={})
 9:         if opts[:topic] && topic_exchange = MockBroker.instance.find_topic_exchange(opts[:topic])
10:           return topic_exchange
11:         end
12:         
13:         if opts[:fanout] && fanout = MockBroker.instance.find_fanout_exchange(opts[:fanout])
14:           return fanout
15:         end
16:         
17:         if opts[:direct] && direct = MockBroker.instance.find_direct_exchange(opts[:direct])
18:           return direct
19:         end
20:         
21:         super
22:       end
new(opts={}) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 26
26:     def initialize(opts={})
27:       if @topic = opts[:topic]
28:         MockBroker.instance.register_topic_exchange(self)
29:       elsif @fanout = opts[:fanout]
30:         MockBroker.instance.register_fanout_exchange(self)
31:       elsif @direct = opts[:direct]
32:         MockBroker.instance.register_direct_exchange(self)
33:       end
34:     end

Public Instance Methods

acked_messages() click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 40
40:     def acked_messages
41:       attached_queues.map do |q|
42:         q = q.first if q.kind_of?(Array)
43:         q.acked_messages
44:       end.flatten
45:     end
attach_queue(queue, opts={}) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 47
47:     def attach_queue(queue, opts={})
48:       if topic
49:         attached_queues << [queue, TopicBindingKey.new(opts[:key])]
50:       elsif direct
51:         attached_queues << [queue, DirectBindingKey.new(opts[:key])]
52:       else
53:         attached_queues << queue
54:       end
55:     end
attached_queues() click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 36
36:     def attached_queues
37:       @attached_queues ||= []
38:     end
publish(message, opts={}) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 57
57:     def publish(message, opts={})
58:       require_routing_key(opts) if topic
59:       matching_queues(opts).each do |q| 
60:         q.receive(message, prepare_header_opts(opts))
61:       end
62:     end
received_ack_for_message?(message) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 64
64:     def received_ack_for_message?(message)
65:       acked_messages.include?(message)
66:     end

Private Instance Methods

matching_queues(opts={}) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 78
78:     def matching_queues(opts={})
79:       return attached_queues unless topic || direct
80:       attached_queues.map {|q, binding| binding.matches?(opts[:key]) ? q : nil}.compact
81:     end
prepare_header_opts(opts={}) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 83
83:     def prepare_header_opts(opts={})
84:       header_opts = opts.dup
85:       if routing_key = header_opts.delete(:key)
86:         header_opts[:routing_key] = routing_key
87:       end
88:       header_opts
89:     end
require_routing_key(opts={}) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 91
91:     def require_routing_key(opts={})
92:       unless opts.has_key?(:key)
93:         raise ArgumentError, "you must provide a key when publishing to a topic exchange"
94:       end
95:     end
routing_keys_match?(binding_key, message_key) click to toggle source
    # File lib/moqueue/mock_exchange.rb, line 70
70:     def routing_keys_match?(binding_key, message_key)
71:       if topic
72:         TopicBindingKey.new(binding_key).matches?(message_key)
73:       elsif direct
74:         DirectBindingKey.new(binding_key).matches?(message_key)
75:       end      
76:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.