Class: ActiveMessaging::Adapters::Test::Connection
- Inherits:
-
BaseConnection
- Object
- BaseConnection
- ActiveMessaging::Adapters::Test::Connection
- Defined in:
- lib/activemessaging/adapters/test.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#connected ⇒ Object
Returns the value of attribute connected.
-
#destinations ⇒ Object
Returns the value of attribute destinations.
-
#received_messages ⇒ Object
Returns the value of attribute received_messages.
-
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
-
#unreceived_messages ⇒ Object
Returns the value of attribute unreceived_messages.
Attributes inherited from BaseConnection
Instance Method Summary collapse
- #all_messages ⇒ Object
- #disconnect ⇒ Object
- #find_destination(destination_name) ⇒ Object
-
#find_message(destination_name, body) ⇒ Object
test helper methods.
- #find_subscription(destination_name) ⇒ Object
-
#initialize(cfg) ⇒ Connection
constructor
A new instance of Connection.
- #open_destination(destination_name) ⇒ Object
- #receive(options = {}) ⇒ Object
- #received(message, headers = {}) ⇒ Object
- #send(destination_name, message_body, message_headers = {}) ⇒ Object
- #subscribe(destination_name, subscribe_headers = {}) ⇒ Object
- #unreceive(message, headers = {}) ⇒ Object
- #unsubscribe(destination_name, unsubscribe_headers = {}) ⇒ Object
Methods included from ActiveMessaging::Adapter
Constructor Details
#initialize(cfg) ⇒ Connection
Returns a new instance of Connection.
12 13 14 15 16 17 18 19 |
# File 'lib/activemessaging/adapters/test.rb', line 12 def initialize cfg @config = cfg @subscriptions = [] @destinations = [] @received_messages = [] @unreceived_messages = [] @connected = true end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/activemessaging/adapters/test.rb', line 10 def config @config end |
#connected ⇒ Object
Returns the value of attribute connected.
10 11 12 |
# File 'lib/activemessaging/adapters/test.rb', line 10 def connected @connected end |
#destinations ⇒ Object
Returns the value of attribute destinations.
10 11 12 |
# File 'lib/activemessaging/adapters/test.rb', line 10 def destinations @destinations end |
#received_messages ⇒ Object
Returns the value of attribute received_messages.
10 11 12 |
# File 'lib/activemessaging/adapters/test.rb', line 10 def @received_messages end |
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
10 11 12 |
# File 'lib/activemessaging/adapters/test.rb', line 10 def subscriptions @subscriptions end |
#unreceived_messages ⇒ Object
Returns the value of attribute unreceived_messages.
10 11 12 |
# File 'lib/activemessaging/adapters/test.rb', line 10 def @unreceived_messages end |
Instance Method Details
#all_messages ⇒ Object
88 89 90 |
# File 'lib/activemessaging/adapters/test.rb', line 88 def @destinations.map {|q| q. }.flatten end |
#disconnect ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/activemessaging/adapters/test.rb', line 21 def disconnect @subscriptions = [] @destinations = [] @received_messages = [] @unreceived_messages = [] @connected = false end |
#find_destination(destination_name) ⇒ Object
80 81 82 |
# File 'lib/activemessaging/adapters/test.rb', line 80 def find_destination destination_name @destinations.find{|q| q.name == destination_name } end |
#find_message(destination_name, body) ⇒ Object
test helper methods
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/activemessaging/adapters/test.rb', line 63 def destination_name, body .find do |m| m.destination == destination_name && if body.is_a?(Regexp) m.body =~ body else m.body == body.to_s end end end |
#find_subscription(destination_name) ⇒ Object
84 85 86 |
# File 'lib/activemessaging/adapters/test.rb', line 84 def find_subscription destination_name @subscriptions.find{|s| s.name == destination_name} end |
#open_destination(destination_name) ⇒ Object
74 75 76 77 78 |
# File 'lib/activemessaging/adapters/test.rb', line 74 def open_destination destination_name unless find_destination destination_name @destinations << Destination.new(destination_name) end end |
#receive(options = {}) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/activemessaging/adapters/test.rb', line 47 def receive(={}) destination = @destinations.find do |q| find_subscription(q.name) && !q.empty? end destination.receive unless destination.nil? end |
#received(message, headers = {}) ⇒ Object
54 55 56 |
# File 'lib/activemessaging/adapters/test.rb', line 54 def received , headers={} @received_messages << end |
#send(destination_name, message_body, message_headers = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/activemessaging/adapters/test.rb', line 41 def send destination_name, , ={} open_destination destination_name destination = find_destination destination_name destination.send Message.new(, nil, , destination_name) end |
#subscribe(destination_name, subscribe_headers = {}) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/activemessaging/adapters/test.rb', line 29 def subscribe destination_name, subscribe_headers={} open_destination destination_name unless @subscriptions.find {|s| s.name == destination_name} @subscriptions << Subscription.new(destination_name, subscribe_headers) end @subscriptions.last end |
#unreceive(message, headers = {}) ⇒ Object
58 59 60 |
# File 'lib/activemessaging/adapters/test.rb', line 58 def unreceive , headers={} @unreceived_messages << end |
#unsubscribe(destination_name, unsubscribe_headers = {}) ⇒ Object
37 38 39 |
# File 'lib/activemessaging/adapters/test.rb', line 37 def unsubscribe destination_name, unsubscribe_headers={} @subscriptions.delete_if {|s| s.name == destination_name} end |