Files

Class/Module Index [+]

Quicksearch

ActiveMessaging::Adapters::Test::Connection

Attributes

config[RW]
connected[RW]
destinations[RW]
received_messages[RW]
subscriptions[RW]
unreceived_messages[RW]

Public Class Methods

new(cfg) click to toggle source
# File lib/activemessaging/adapters/test.rb, line 12
def initialize cfg
  @config = cfg
  @subscriptions = []
  @destinations = []
  @received_messages = []
  @unreceived_messages = []
  @connected = true
end

Public Instance Methods

all_messages() click to toggle source
# File lib/activemessaging/adapters/test.rb, line 88
def all_messages
  @destinations.map {|q| q.messages }.flatten
end
disconnect() click to toggle source
# File lib/activemessaging/adapters/test.rb, line 21
def disconnect
  @subscriptions = []
  @destinations = []
  @received_messages = []
  @unreceived_messages = []
  @connected = false
end
find_destination(destination_name) click to toggle source
# 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) click to toggle source

test helper methods

# File lib/activemessaging/adapters/test.rb, line 63
def find_message destination_name, body
  
  all_messages.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) click to toggle source
# 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) click to toggle source
# 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={}) click to toggle source
# File lib/activemessaging/adapters/test.rb, line 47
def receive(options={})
  destination = @destinations.find do |q|
    find_subscription(q.name) && !q.empty?
  end
  destination.receive unless destination.nil?
end
received(message, headers={}) click to toggle source
# File lib/activemessaging/adapters/test.rb, line 54
def received message, headers={}
  @received_messages << message
end
send(destination_name, message_body, message_headers={}) click to toggle source
# File lib/activemessaging/adapters/test.rb, line 41
def send destination_name, message_body, message_headers={}
  open_destination destination_name
  destination = find_destination destination_name
  destination.send Message.new(message_body, nil, message_headers, destination_name)
end
subscribe(destination_name, subscribe_headers={}) click to toggle source
# 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={}) click to toggle source
# File lib/activemessaging/adapters/test.rb, line 58
def unreceive message, headers={}
  @unreceived_messages << message
end
unsubscribe(destination_name, unsubscribe_headers={}) click to toggle source
# File lib/activemessaging/adapters/test.rb, line 37
def unsubscribe destination_name, unsubscribe_headers={}
  @subscriptions.delete_if {|s| s.name == destination_name}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.