You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:42:52 UTC

svn commit: r962277 - in /incubator/deltacloud/trunk/server: lib/deltacloud/hardware_profile.rb lib/deltacloud/helpers/hardware_profiles_helper.rb views/hardware_profiles/index.html.haml views/hardware_profiles/show.html.haml

Author: lutter
Date: Thu Jul  8 23:42:51 2010
New Revision: 962277

URL: http://svn.apache.org/viewvc?rev=962277&view=rev
Log:
Hardware profiles: slight revamp to make XML generation easier

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb
    incubator/deltacloud/trunk/server/views/hardware_profiles/index.html.haml
    incubator/deltacloud/trunk/server/views/hardware_profiles/show.html.haml

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb?rev=962277&r1=962276&r2=962277&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb Thu Jul  8 23:42:51 2010
@@ -2,40 +2,55 @@
 module Deltacloud
   class HardwareProfile
 
+    class Property
+      attr_reader :name, :kind
+      # kind == :range
+      attr_reader :first, :last
+      # kind == :enum
+      attr_reader :values
+      # kind == :fixed
+      attr_reader :value
+
+      def initialize(name, values)
+        @name = name
+        if values.is_a?(Range)
+          @kind = :range
+          @first = values.first
+          @last = values.last
+        elsif values.is_a?(Array)
+          @kind = :enum
+          @values = values
+        else
+          @kind = :fixed
+          @value = values
+        end
+      end
+    end
+
+    class << self
+      def property(prop)
+        define_method(prop) do |*args|
+          values, *ignored = *args
+          instvar = :"@#{prop}"
+          unless values.nil?
+            @properties[prop] = Property.new(prop, values)
+          end
+          @properties[prop]
+        end
+      end
+    end
+
     attr_reader :name
-    attr_reader :cpu
-    attr_reader :architecture
-    attr_reader :memory
-    attr_reader :storage
+    property :cpu
+    property :architecture
+    property :memory
+    property :storage
 
     def initialize(name,&block)
+      @properties   = {}
       @name         = name
-      @cpu          = 1
-      @memory       = 0
-      @storage      = 0
-      @architecture = 1
       @mutable      = false
-      instance_eval &block
-    end
-
-    def cpu(values=nil)
-      ( @cpu = values ) unless values.nil?
-      @cpu
-    end
-
-    def architecture(values=nil)
-      ( @architecture = values ) unless values.nil?
-      @architecture
-    end
-
-    def memory(values=nil)
-      ( @memory = values ) unless values.nil?
-      @memory
-    end
-
-    def storage(values=nil)
-      ( @storage = values ) unless values.nil?
-      @storage
+      instance_eval &block if block_given?
     end
 
     def mutable
@@ -50,5 +65,8 @@ module Deltacloud
       @mutable
     end
 
+    def each_property(&block)
+      @properties.each_value { |prop| yield prop }
+    end
   end
 end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb?rev=962277&r1=962276&r2=962277&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb Thu Jul  8 23:42:51 2010
@@ -1,16 +1,15 @@
 module HardwareProfilesHelper
 
-  def format_hardware_aspect(values)
-    f = ''
-    case ( values )
-      when Range
-        f = "#{values.begin} - #{values.end}"
-      when Array
-        f = values.join( ', ' )
+  def format_hardware_property(prop)
+    return "&empty;" unless prop
+    case prop.kind
+      when :range
+        "#{prop.first} - #{prop.last}"
+      when :enum
+        prop.values.join(', ')
       else
-        f = values.to_s
+        prop.value.to_s
     end
-    f
   end
 
 end

Modified: incubator/deltacloud/trunk/server/views/hardware_profiles/index.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/hardware_profiles/index.html.haml?rev=962277&r1=962276&r2=962277&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/hardware_profiles/index.html.haml (original)
+++ incubator/deltacloud/trunk/server/views/hardware_profiles/index.html.haml Thu Jul  8 23:42:51 2010
@@ -20,10 +20,10 @@
         %td
           = link_to profile.name, hardware_profile_url( profile.name )
         %td
-          = profile.architecture
+          = format_hardware_property profile.architecture
         %td
-          = format_hardware_aspect profile.memory
+          = format_hardware_property profile.memory
         %td
-          = format_hardware_aspect profile.storage
+          = format_hardware_property profile.storage
         %td
           = profile.mutable?

Modified: incubator/deltacloud/trunk/server/views/hardware_profiles/show.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/hardware_profiles/show.html.haml?rev=962277&r1=962276&r2=962277&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/hardware_profiles/show.html.haml (original)
+++ incubator/deltacloud/trunk/server/views/hardware_profiles/show.html.haml Thu Jul  8 23:42:51 2010
@@ -6,17 +6,17 @@
     %dt
       Architecture
     %dd
-      = @profile.architecture
+      = format_hardware_property @profile.architecture
   %di
     %dt
       Memory
     %dd
-      = format_hardware_aspect @profile.memory
+      = format_hardware_property @profile.memory
   %di
     %dt
       Storage
     %dd
-      = format_hardware_aspect @profile.storage
+      = format_hardware_property @profile.storage
   %di
     %dt
       Mutable