Class: Adaptation::Adaptor

Inherits:
Object show all
Defined in:
lib/adaptation/adaptor.rb

Overview

Adaptation::Adaptor – The message processor

Adaptation::Adaptor is the base class for those classes containing the logic to be executed when a message is read through the mom.

Each class extending Adaptation::Adaptor must implement the process function, using it as the main entry point for the logic to be executed when a message arrives. The name of the class extending Adaptation::Message associates the class with the one to be executed when a message arrives. Ie. if a message is received with a root element named <hello>, adaptation will search for a class extending Adaptation::Adaptor named HelloAdaptor.

Adaptation::Adaptors (classes extending Adaptation::Adaptor) must be stored under app/adaptors_name in the adaptation file tree. This is done automatically when an adaptor is generated using adaptation built-in generator:

script/generate adaptor hello

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_class_object(adaptor_class) ⇒ Object

nodoc



40
41
42
# File 'lib/adaptation/adaptor.rb', line 40

def self.get_class_object(adaptor_class) # nodoc
  Object.const_get(adaptor_class) rescue nil
end

Instance Method Details

#loggerObject



16
17
18
# File 'lib/adaptation/adaptor.rb', line 16

def logger
  Adaptation::Base.logger
end

#process(message) ⇒ Object



13
14
# File 'lib/adaptation/adaptor.rb', line 13

def process message
end

#publish(*options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/adaptation/adaptor.rb', line 20

def publish *options
  message_object = nil
  if options.first.is_a?(Message)
    message_object = options.first
  elsif options.first.is_a?(String)
    xml_message = options.first
    message_type = xml_message[1..(xml_message.index(/(>| )/) - 1)]
    message_class = Adaptation::Message.get_class_object(message_type.capitalize)
    message_object = message_class.to_object(xml_message)
  end
  
  xml = message_object.to_xml.to_s.gsub("'", "\"")
  publish_method = $config["oappublish"] || "#{ADAPTOR_ROOT}/script/publish"
  topic = $config["application"] || "ADAPTATION"
  unless system("#{publish_method} '#{$config["application"]}' '#{xml}'")
    logger.error "Problem publishing: #{xml}"
  end

end