On 07/02/2010 08:23 AM, Jan Provaznik wrote:
On 07/01/2010 07:17 PM, Tomas Sedovic wrote:
Hey everyone,

The current Core and Aggregator versions are not working with each
other. I started looking at it, but couldn't finish it today. Since I
won't get to it before Wednesday July 7, here's what I found in case
anybody wants to pick it up.

If not, I'll resume working on it on Wednesday.


Hi,
great work. I'll look on compatibility issues today and report
a progress (if any) to this thread this evening.

Jan

Some notes about issues I found:
major problem with new client lib is conflict with names of some methods/classes.

Client overrides some rails methods like classify, camelize, singularize,... I suggest to wrap it by method_defined?. Attached patch replaces Tomas core patch (singularize method rename).

Unfortunately another problem is class names conflict.
Client dynamically adds classes (like HardwareProfile), which conflict with our model names. But I didn't figure out why, code in client seems to be correct on first look (see define_class method at the end) - it creates classes in DeltaCloud module. But in fact it overrides model class. Provider is then created, but hardware profiles properties are not saved.

I'll discuss it with Michal next Wednesday.

Jan
>From 99a51b097df941864c204cf6995a1ea25ffb6565 Mon Sep 17 00:00:00 2001
From: Jan Provaznik <[email protected]>
Date: Fri, 2 Jul 2010 17:08:26 +0200
Subject: [PATCH] wraps String method overridings

---
 client/lib/deltacloud.rb |   42 ++++++++++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index 19b6093..445b844 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -470,30 +470,40 @@ end
 
 class String
 
-  # Create a class name from string
-  def classify
-    self.singularize.camelize
+  unless method_defined?(:classify)
+    # Create a class name from string
+    def classify
+      self.singularize.camelize
+    end
   end
 
-  # Camelize converts strings to UpperCamelCase
-  def camelize
-    self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { 
$1.upcase }
+  unless method_defined?(:camelize)
+    # Camelize converts strings to UpperCamelCase
+    def camelize
+      self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { 
$1.upcase }
+    end
   end
 
-  # Strip 's' character from end of string
-  def singularize
-    self.gsub(/s$/, '')
+  unless method_defined?(:singularize)
+    # Strip 's' character from end of string
+    def singularize
+      self.gsub(/s$/, '')
+    end
   end
 
-  # Convert string to float if string value seems like Float
-  def convert
-    return self.to_f if self.strip =~ /^([\d\.]+$)/
-    self
+  unless method_defined?(:convert)
+    # Convert string to float if string value seems like Float
+    def convert
+      return self.to_f if self.strip =~ /^([\d\.]+$)/
+      self
+    end
   end
 
-  # Simply converts whitespaces and - symbols to '_' which is safe for Ruby
-  def sanitize
-    self.gsub(/(\W+)/, '_')
+  unless method_defined?(:sanitize)
+    # Simply converts whitespaces and - symbols to '_' which is safe for Ruby
+    def sanitize
+      self.gsub(/(\W+)/, '_')
+    end
   end
 
 end
-- 
1.7.0.1

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to