deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 5/5] CIMI: Added ability to convert to JSON/XML when certain properties are not set
Date Wed, 23 Nov 2011 16:23:25 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/model/schema.rb |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/server/lib/cimi/model/schema.rb b/server/lib/cimi/model/schema.rb
index 46d537b..b6237e3 100644
--- a/server/lib/cimi/model/schema.rb
+++ b/server/lib/cimi/model/schema.rb
@@ -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
-- 
1.7.4.4


Mime
View raw message