Class: Adaptation::Adaptor

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

Overview

script/generate adaptor hello

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_class_object(adaptor_class) ⇒ Object

:nodoc:



57
58
59
# File 'lib/adaptation/adaptor.rb', line 57

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

Instance Method Details

#loggerObject

Returns the logger to output results in the current environment log file. Example:

> logger.info "this is going to log/development.log"


19
20
21
# File 'lib/adaptation/adaptor.rb', line 19

def logger
  Adaptation::Base.logger
end

#process(message) ⇒ Object

:nodoc:



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

def process message #:nodoc:
end

#publish(*options) ⇒ Object

Publishes a message to the MOM. The message can be an instance of Adaptation::Message or a String.

When executed in test environment messages are not published to the MOM. They are written to a mocked MOM and their publication can be asserted in tests with assert_message_published.

By default it uses script/publish ito publish. This can be overwritten specifying the oappublish instruction in configuration file config/settings.yml.

By default it publishes in topic ADAPTATION. This can be overwritten specifying the application setting in config/settings.yml file.

Example settings file:

oappublish: /bin/echo
application: MY_TOPIC


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/adaptation/adaptor.rb', line 37

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.new(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