Commits

Yuya Nishihara committed 42e02d6

made it simple to access message[] or report[]

  • Participants
  • Parent commits aead3d0

Comments (0)

Files changed (1)

File lib/tasks/import_kagemai_reports.rake

     end
 
     def self.map_priority(kagemai_proj_id, report)
-      return Enumeration.default('IPRI') unless report.first.has_element? 'priority'
       prio = encode(report['priority'])
+      return Enumeration.default('IPRI') if prio.to_s.empty?
       Enumeration.find(:first, :conditions => ['opt = ? AND name = ?', 'IPRI', PRIORITY_MAP[prio] || prio]) \
           or raise "unknown priority: #{prio}"
     end
   end
 
   KagemaiImport.initialize()
+
+  # after loading Kagemai module by KagemaiImport.initialize()
+  module Kagemai
+    class Message
+      alias orig_element_value []
+      def [](id)  # gracefully
+        begin
+          orig_element_value(id)
+        rescue NoSuchElementError
+          nil
+        end
+      end
+    end
+
+    class Report
+      def [](name)  # gracefully
+        begin
+          attr(name)
+        rescue NoSuchElementError
+          nil
+        end
+      end
+    end
+  end
+
   ActiveRecord::Base.transaction do
     KagemaiImport.import_project(ENV['project'], ENV['first'], ENV['last'])
   end