deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1205814 - /deltacloud/trunk/server/lib/cimi/model/schema.rb
Date Thu, 24 Nov 2011 13:19:16 GMT
Author: mfojtik
Date: Thu Nov 24 13:19:15 2011
New Revision: 1205814

URL: http://svn.apache.org/viewvc?rev=1205814&view=rev
Log:
CIMI: Added ability to convert to JSON/XML when certain properties are not set

Modified:
    deltacloud/trunk/server/lib/cimi/model/schema.rb

Modified: deltacloud/trunk/server/lib/cimi/model/schema.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/schema.rb?rev=1205814&r1=1205813&r2=1205814&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/schema.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/schema.rb Thu Nov 24 13:19:15 2011
@@ -68,6 +68,7 @@ class CIMI::Model::Schema
     end
 
     def to_xml(model, xml)
+      return unless model
       return unless model[@name]
       case @text
         when :nested then xml[@xml_name] = [{ "content" => model[@name] }]
@@ -160,12 +161,12 @@ class CIMI::Model::Schema
     end
 
     def to_xml(model, xml)
-      ary = model[name].map { |elt| @struct.convert_to_xml(elt) }
+      ary = (model[name] || []).map { |elt| @struct.convert_to_xml(elt) }
       xml[xml_name] = ary unless ary.empty?
     end
 
     def to_json(model, json)
-      ary = model[name].map { |elt| @struct.convert_to_json(elt) }
+      ary = (model[name] || []).map { |elt| @struct.convert_to_json(elt) }
       json[json_name] = ary unless ary.empty?
     end
   end
@@ -189,12 +190,12 @@ class CIMI::Model::Schema
     end
 
     def to_xml(model, xml)
-      ary = model[name].map { |elt| @struct.convert_to_xml(elt) }
+      ary = (model[name] || []).map { |elt| @struct.convert_to_xml(elt) }
       xml[xml_name] = ary unless ary.empty?
     end
 
     def to_json(model, json)
-      ary = model[name].map { |elt| @struct.convert_to_json(elt) }
+      ary = (model[name] || []).map { |elt| @struct.convert_to_json(elt) }
       json[json_name] = ary.inject({}) { |result, item| result[item['name']] = item['value'];
result } unless ary.empty?
     end
   end



Mime
View raw message