deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 3/6] CIMI (schema): take explicit xml_name and json_name verbatim
Date Sat, 11 Aug 2012 01:03:24 GMT
From: David Lutterkort <lutter@redhat.com>

We used to camelize them, which is not always the right thing (for example,
it's impossible to produce a tag "baseURI" that way)
---
 server/lib/cimi/models/schema.rb                 |   10 ++++++----
 server/tests/cimi/spec/cimi/model/schema_spec.rb |    2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index fa0d11a..a0e4637 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -25,8 +25,8 @@ class CIMI::Model::Schema
 
     def initialize(name, opts = {})
       @name = name
-      @xml_name = (opts[:xml_name] || name).to_s.camelize(true)
-      @json_name = (opts[:json_name] || name).to_s.camelize(true)
+      @xml_name = opts[:xml_name] || name.to_s.camelize(true)
+      @json_name = opts[:json_name] || name.to_s.camelize(true)
     end
 
     def from_xml(xml, model)
@@ -144,10 +144,12 @@ class CIMI::Model::Schema
   end
 
   class Array < Attribute
-    # For an array :things, we collect all <thing/> elements (XmlSimple
+    # For an array :funThings, we collect all <funThing/> elements (XmlSimple
     # actually does the collecting)
     def initialize(name, opts = {}, &block)
-      opts[:xml_name] = name.to_s.singularize unless opts[:xml_name]
+      unless opts[:xml_name]
+        opts[:xml_name] = name.to_s.singularize.camelize.uncapitalize
+      end
       super(name, opts)
       @struct = Struct.new(name, opts, &block)
     end
diff --git a/server/tests/cimi/spec/cimi/model/schema_spec.rb b/server/tests/cimi/spec/cimi/model/schema_spec.rb
index 8b6de48..0672e59 100644
--- a/server/tests/cimi/spec/cimi/model/schema_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/schema_spec.rb
@@ -62,7 +62,7 @@ describe "Schema" do
     end
 
     it "should allow aliasing the XML and JSON name" do
-      @schema.scalar :aliased, :xml_name => :xml, :json_name => :json
+      @schema.scalar :aliased, :xml_name => "xml", :json_name => "json"
       obj = @schema.from_xml({"aliased" => "no", "xml" => "yes"}, {})
       obj[:aliased].must_equal "yes"
 
-- 
1.7.7.6


Mime
View raw message