deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [1/6] git commit: CIMI (schema): take explicit xml_name and json_name verbatim
Date Tue, 14 Aug 2012 21:47:25 GMT
Updated Branches:
  refs/heads/master 0f11c3306 -> c25145860


CIMI (schema): take explicit xml_name and json_name verbatim

We used to camelize them, which is not always the right thing (for example,
it's impossible to produce a tag "baseURI" that way)


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/10ab7ae3
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/10ab7ae3
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/10ab7ae3

Branch: refs/heads/master
Commit: 10ab7ae3882aead1eef8759dd8ade4198d40ce92
Parents: 2ca0a20
Author: David Lutterkort <lutter@redhat.com>
Authored: Fri Aug 10 17:43:57 2012 -0700
Committer: David Lutterkort <lutter@redhat.com>
Committed: Tue Aug 14 14:44:18 2012 -0700

----------------------------------------------------------------------
 server/lib/cimi/models/schema.rb                 |   10 ++++++----
 server/tests/cimi/spec/cimi/model/schema_spec.rb |    2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/10ab7ae3/server/lib/cimi/models/schema.rb
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/10ab7ae3/server/tests/cimi/spec/cimi/model/schema_spec.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/spec/cimi/model/schema_spec.rb b/server/tests/cimi/spec/cimi/model/schema_spec.rb
index 0a9dd9c..2b82e36 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"
 


Mime
View raw message