deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [2/4] git commit: Core: Removed obsoleted to_hash serialization and minor fixes in models
Date Wed, 18 Jul 2012 08:27:46 GMT
Core: Removed obsoleted to_hash serialization and minor fixes in models


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

Branch: refs/heads/master
Commit: 2c9c6d68849673107eb06941d396498632c84178
Parents: 5742415
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Tue Jul 17 15:50:42 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Wed Jul 18 10:28:11 2012 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/models/address.rb          |    2 +-
 server/lib/deltacloud/models/base_model.rb       |   14 -------
 server/lib/deltacloud/models/bucket.rb           |   10 -----
 server/lib/deltacloud/models/hardware_profile.rb |   31 +++--------------
 server/lib/deltacloud/models/image.rb            |   12 ------
 server/lib/deltacloud/models/instance.rb         |   18 +---------
 server/lib/deltacloud/models/key.rb              |    4 +-
 server/lib/deltacloud/models/metric.rb           |    2 +-
 8 files changed, 10 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2c9c6d68/server/lib/deltacloud/models/address.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/address.rb b/server/lib/deltacloud/models/address.rb
index dbabb08..7054a77 100644
--- a/server/lib/deltacloud/models/address.rb
+++ b/server/lib/deltacloud/models/address.rb
@@ -22,7 +22,7 @@ class Address < BaseModel
   end
 
   def associated?
-    true unless self.instance_id.nil?
+    !self.instance_id.nil?
   end
 
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2c9c6d68/server/lib/deltacloud/models/base_model.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/base_model.rb b/server/lib/deltacloud/models/base_model.rb
index b122b2b..5c19ad5 100644
--- a/server/lib/deltacloud/models/base_model.rb
+++ b/server/lib/deltacloud/models/base_model.rb
@@ -44,18 +44,4 @@ class BaseModel
     @id
   end
 
-  def to_hash
-    out = {}
-    self.attributes.each do |attribute|
-      if self.send(:"#{attribute}")
-        out.merge!({ attribute => self.send(:"#{attribute}") } )
-      end
-    end
-    out
-  end
-
-  def to_json(*a)
-    self.to_hash.to_json(*a)
-  end
-
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2c9c6d68/server/lib/deltacloud/models/bucket.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/bucket.rb b/server/lib/deltacloud/models/bucket.rb
index 0c21c21..0309628 100644
--- a/server/lib/deltacloud/models/bucket.rb
+++ b/server/lib/deltacloud/models/bucket.rb
@@ -20,18 +20,8 @@ class Bucket < BaseModel
   attr_accessor :size
   attr_accessor :blob_list
 
-  alias :to_hash_original :to_hash
-
   def blob_list
     @blob_list || []
   end
 
-  def to_hash
-    h = self.to_hash_original
-    unless blob_list.nil?
-      h[:blob_list] = self.blob_list.collect { |blob| { :id => blob,
-        :href => "#{settings.root_url}/buckets/#{self.id}/#{blob}"}}
-    end
-    return h
-  end
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2c9c6d68/server/lib/deltacloud/models/hardware_profile.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/hardware_profile.rb b/server/lib/deltacloud/models/hardware_profile.rb
index 0b36c4b..f9678b0 100644
--- a/server/lib/deltacloud/models/hardware_profile.rb
+++ b/server/lib/deltacloud/models/hardware_profile.rb
@@ -154,35 +154,14 @@ module Deltacloud
     end
 
     def default?(prop, v)
-      p = @properties[prop.to_sym]
-      p && p.default.to_s == v
-    end
-
-    def to_hash
-      props = []
-      self.each_property do |p|
-        if p.kind.eql? :fixed
-          props << { :kind => p.kind, :value => p.value, :name => p.name,
:unit => p.unit }
-        else
-          param = { :operation => "create", :method => "post", :name => p.name }
-          if p.kind.eql? :range
-            param[:range] = { :first => p.first, :last => p.last }
-          elsif p.kind.eql? :enum
-            param[:enum] = p.values.collect { |v| { :entry => v } }
-          end
-          param
-          props << { :kind => p.kind, :value => p.default, :name => p.name,
:unit => p.unit, :param => param }
-        end
-      end
-      {
-        :id => self.name,
-        :properties => props
-      }
+      property(prop) && property(prop).default.to_s == v
     end
 
     def include?(prop, v)
-      p = @properties[prop]
-      p.nil? || p.include?(v)
+      return false unless p = property(prop)
+      return true if p.kind == :range and (p.first..p.last).include?(v)
+      return true if p.kind == :enum and p.values.include?(v)
+      false
     end
 
     def params

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2c9c6d68/server/lib/deltacloud/models/image.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/image.rb b/server/lib/deltacloud/models/image.rb
index 555004e..f9a64e1 100644
--- a/server/lib/deltacloud/models/image.rb
+++ b/server/lib/deltacloud/models/image.rb
@@ -24,16 +24,4 @@ class Image < BaseModel
   attr_accessor :state
   attr_accessor :hardware_profiles
 
-  alias :to_hash_original :to_hash
-
-  def to_hash
-    h = self.to_hash_original
-    h.merge({
-      :actions => [ :create_instance => {
-        :method => 'post',
-        :href => "#{settings.root_url}/instances;image_id=#{self.id}"
-      }]
-    })
-  end
-
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2c9c6d68/server/lib/deltacloud/models/instance.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
index 9db5b4b..303691d 100644
--- a/server/lib/deltacloud/models/instance.rb
+++ b/server/lib/deltacloud/models/instance.rb
@@ -63,7 +63,7 @@ class Instance < BaseModel
 
   def method_missing(name, *args)
     if name =~ /is_(\w+)\?/
-      return true if self.state.downcase.eql?($1)
+      self.state.downcase.eql?($1)
     else
       raise NoMethodError.new(name.to_s)
     end
@@ -73,20 +73,4 @@ class Instance < BaseModel
     return true unless authn_error.nil?
   end
 
-  alias :to_hash_original :to_hash
-
-  def to_hash
-    h = self.to_hash_original
-    h[:public_addresses] = h[:public_addresses].collect do |address|
-      { :address => { :type => address.address_type, :value => address } }
-    end
-    h[:actions] = self.actions.collect do |action|
-      { :"#{action}" => {
-        :method => collections[:instances].operations[action.to_sym].method,
-        :href => collections[:instances].operations[action.to_sym].path.gsub(':id', self.id)
-      }}
-    end
-    h
-  end
-
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2c9c6d68/server/lib/deltacloud/models/key.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/key.rb b/server/lib/deltacloud/models/key.rb
index 64c4cc7..388c14a 100644
--- a/server/lib/deltacloud/models/key.rb
+++ b/server/lib/deltacloud/models/key.rb
@@ -28,11 +28,11 @@ class Key < BaseModel
   end
 
   def is_password?
-    true if @credential_type.eql?(:password)
+    @credential_type.eql?(:password)
   end
 
   def is_key?
-    true if @credential_type.eql?(:key)
+    @credential_type.eql?(:key)
   end
 
   # Mock fingerprint generator

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2c9c6d68/server/lib/deltacloud/models/metric.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/metric.rb b/server/lib/deltacloud/models/metric.rb
index 42edaaf..f6f3822 100644
--- a/server/lib/deltacloud/models/metric.rb
+++ b/server/lib/deltacloud/models/metric.rb
@@ -19,7 +19,7 @@ class Metric < BaseModel
   attr_accessor :properties
 
   def unknown?
-    true if self.entity == :unknown
+    self.entity == :unknown
   end
 
   def add_property(name, values=nil)


Mime
View raw message