You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/24 12:10:26 UTC
[PATCH core 3/5] CIMI: Added ability to convert to JSON/XML when certain properties are not set
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@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