Class: Adaptation::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



43
44
45
46
47
48
49
50
# File 'lib/adaptation/base.rb', line 43

def initialize 
  
  Initializer.run

  @@logger = Logger.new("#{ADAPTOR_ROOT}/log/#{ADAPTOR_ENV}.log")
  ActiveRecord::Base.logger = @@logger
  
end

Class Method Details

.loggerObject



52
53
54
# File 'lib/adaptation/base.rb', line 52

def self.logger
  @@logger
end

Instance Method Details

#process(xml_message) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/adaptation/base.rb', line 56

def process(xml_message)

  # dirty method to discover the message type
  # TODO: move to a module
  message_type = xml_message[1..(xml_message.index(/(>| |\/)/) - 1)]
  adaptor = message = nil
 
  message_class = Adaptation::Message.get_class_object(message_type.capitalize)
  message = message_class.nil? ? Adaptation::Message.new(xml_message) : message_class.new(xml_message)
    
  adaptor_class = Adaptation::Adaptor.get_class_object("#{message_type.capitalize}Adaptor")    
  adaptor = adaptor_class.nil? ? ApplicationAdaptor.new : adaptor_class.new rescue Adaptation::Adaptor.new

  unless message.valid?
    @@logger.info "WARNING:Message doesn't validate!" 
    return
  end

  adaptor.process message
end