deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1202672 - in /incubator/deltacloud/trunk/server/lib/cimi: model.rb model/base.rb model/schema.rb
Date Wed, 16 Nov 2011 12:48:41 GMT
Author: mfojtik
Date: Wed Nov 16 12:48:40 2011
New Revision: 1202672

URL: http://svn.apache.org/viewvc?rev=1202672&view=rev
Log:
CIMI: Replaced elsif by case, switched block syntax

Modified:
    incubator/deltacloud/trunk/server/lib/cimi/model.rb
    incubator/deltacloud/trunk/server/lib/cimi/model/base.rb
    incubator/deltacloud/trunk/server/lib/cimi/model/schema.rb

Modified: incubator/deltacloud/trunk/server/lib/cimi/model.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/model.rb?rev=1202672&r1=1202671&r2=1202672&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/model.rb (original)
+++ incubator/deltacloud/trunk/server/lib/cimi/model.rb Wed Nov 16 12:48:40 2011
@@ -14,6 +14,8 @@
 # under the License.
 #
 
+# Declare namespace for CIMI model
+#
 module CIMI
   module Model; end
 end

Modified: incubator/deltacloud/trunk/server/lib/cimi/model/base.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/model/base.rb?rev=1202672&r1=1202671&r2=1202672&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/model/base.rb (original)
+++ incubator/deltacloud/trunk/server/lib/cimi/model/base.rb Wed Nov 16 12:48:40 2011
@@ -163,7 +163,7 @@ class CIMI::Model::Base
   text :uri, :name, :description, :created
 
   # FIXME: this doesn't match with JSON
-  array :properties, :content => :value do
-    scalar :key
+  array :property, :content => :value do
+    scalar :name
   end
 end

Modified: incubator/deltacloud/trunk/server/lib/cimi/model/schema.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/model/schema.rb?rev=1202672&r1=1202671&r2=1202672&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/model/schema.rb (original)
+++ incubator/deltacloud/trunk/server/lib/cimi/model/schema.rb Wed Nov 16 12:48:40 2011
@@ -60,23 +60,19 @@ class CIMI::Model::Schema
     def nested_text?; @text == :nested; end
 
     def from_xml(xml, model)
-      if @text == :nested
-        model[@name] = xml[@xml_name].first["content"] if xml[@xml_name]
-      elsif @text == :direct
-        model[@name] = xml["content"]
-      else
-        model[@name] = xml[@xml_name]
+      case @text
+        when :nested : model[@name] = xml[@xml_name].first["content"] if xml[@xml_name]
+        when :direct : model[@name] = xml["content"]
+        else model[@name] = xml[@xml_name]
       end
     end
 
     def to_xml(model, xml)
       return unless model[@name]
-      if @text == :nested
-        xml[@xml_name] = [{ "content" => model[@name] }]
-      elsif @text == :direct
-        xml["content"] = model[@name]
-      else
-        xml[@xml_name] = model[@name]
+      case @text
+        when :nested : xml[@xml_name] = [{ "content" => model[@name] }]
+        when :direct : xml["content"] = model[@name]
+        else xml[@xml_name] = model[@name]
       end
     end
   end
@@ -84,7 +80,7 @@ class CIMI::Model::Schema
   class Struct < Attribute
     def initialize(name, opts, &block)
       content = opts[:content]
-      super(name)
+      super(name, opts)
       @schema = CIMI::Model::Schema.new
       @schema.instance_eval(&block) if block_given?
       @schema.scalar(content, :text => :direct) if content
@@ -156,15 +152,11 @@ class CIMI::Model::Schema
     end
 
     def from_xml(xml, model)
-      model[name] = (xml[xml_name] || []).map do |elt|
-        @struct.convert_from_xml(elt)
-      end
+      model[name] = (xml[xml_name] || []).map { |elt| @struct.convert_from_xml(elt) }
     end
 
     def from_json(json, model)
-      model[name] = (json[json_name] || []).map do |elt|
-        @struct.convert_from_json(elt)
-      end
+      model[name] = (json[json_name] || []).map { |elt| @struct.convert_from_json(elt) }
     end
 
     def to_xml(model, xml)
@@ -220,9 +212,7 @@ class CIMI::Model::Schema
   # +add_attributes!+ method
   module DSL
     def href(*args)
-      args.each do |arg|
-        struct(arg) { scalar :href }
-      end
+      args.each { |arg| struct(arg) { scalar :href } }
     end
 
     def text(*args)
@@ -246,12 +236,8 @@ class CIMI::Model::Schema
   include DSL
 
   def add_attributes!(args, attr_klass, &block)
-    if @attributes.frozen?
-      raise "The schema has already been used to convert objects"
-    end
+    raise "The schema has already been used to convert objects" if @attributes.frozen?
     opts = args.extract_opts!
-    args.each do |arg|
-      @attributes << attr_klass.new(arg, opts, &block)
-    end
+    args.each { |arg| @attributes << attr_klass.new(arg, opts, &block) }
   end
 end



Mime
View raw message