You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by dk...@apache.org on 2013/03/28 12:13:01 UTC
git commit: CIMI schema: tolerate nil hash_map attributes
Updated Branches:
refs/heads/master fcffad13e -> ae03fbf77
CIMI schema: tolerate nil hash_map attributes
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/ae03fbf7
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/ae03fbf7
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/ae03fbf7
Branch: refs/heads/master
Commit: ae03fbf77464e226fed40997b401b781b76f11cb
Parents: fcffad1
Author: David Lutterkort <lu...@redhat.com>
Authored: Wed Mar 27 12:26:36 2013 -0700
Committer: Dies Koper <di...@fast.au.fujitsu.com>
Committed: Thu Mar 28 22:12:30 2013 +1100
----------------------------------------------------------------------
server/lib/cimi/models/schema.rb | 28 ++++++++++++++++++++++------
1 files changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ae03fbf7/server/lib/cimi/models/schema.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index 5a2049b..8dd309c 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -124,12 +124,12 @@ class CIMI::Model::Schema
end
def to_xml(model, xml)
- conv = convert_to_xml(model[name])
+ conv = convert_to_xml(extract(model))
xml[xml_name] = [conv] unless conv.empty?
end
def to_json(model, json)
- conv = convert_to_json(model[name])
+ conv = convert_to_json(extract(model))
json[json_name] = conv unless conv.empty?
end
@@ -179,6 +179,14 @@ class CIMI::Model::Schema
@struct_class ||= ::Struct.new(nil, *@schema.attribute_names)
end
end
+ def extract(model)
+ if model.respond_to?("[]")
+ model[name] || {}
+ else
+ {}
+ end
+ end
+
end
class Ref < CIMI::Model::Schema::Struct
@@ -268,13 +276,21 @@ class CIMI::Model::Schema
end
def to_xml(model, xml)
- ary = (model[name] || {}).map { |k, v| { "key" => k, "content" => v } }
- xml[xml_name] = ary unless ary.empty?
+ mapped = extract(model).map { |k, v| { "key" => k, "content" => v } }
+ xml[xml_name] = mapped unless mapped.empty?
end
def to_json(model, json)
- if model[name] && ! model[name].empty?
- json[json_name] = model[name]
+ h = extract(model)
+ json[json_name] = h unless h.empty?
+ end
+
+ private
+ def extract(model)
+ if model.respond_to?("[]")
+ model[name] || {}
+ else
+ {}
end
end
end