incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 4/5] Fixed class spawning to be compatible with Rails
Date Tue, 19 Oct 2010 13:36:02 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 client/lib/base_object.rb |   22 ++++++++++------------
 client/lib/deltacloud.rb  |    9 +++++----
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/client/lib/base_object.rb b/client/lib/base_object.rb
index b269bb8..02967ae 100644
--- a/client/lib/base_object.rb
+++ b/client/lib/base_object.rb
@@ -16,7 +16,7 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-require 'lib/string'
+require 'string'
 
 module DeltaCloud
 
@@ -256,18 +256,16 @@ module DeltaCloud
 
     def self.add_class(name, parent=:base)
       parent_class = case parent
-        when :base then BaseObject
-        when :action then ActionObject
-        when :state then StateFullObject
+        when :base then 'BaseObject'
+        when :action then 'ActionObject'
+        when :state then 'StateFullObject'
       end
-      begin
-        return API.const_get(name.classify)
-      rescue NameError
-        API.module_eval("class #{name.classify} < #{parent_class.to_s}; end")
-        new_class = API.const_get(name.classify)
-        @defined_classes ||= []
-        @defined_classes << new_class
-        new_class
+      @defined_classes ||= []
+      if @defined_classes.include?(name)
+        DeltaCloud::API.class_eval("#{name.classify}")
+      else
+        DeltaCloud::API.class_eval("class #{name.classify} < DeltaCloud::#{parent_class};
end")
+        DeltaCloud::API.const_get("#{name.classify}")
       end
     end
 
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index 5c224e5..f797223 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -20,10 +20,11 @@ require 'nokogiri'
 require 'rest_client'
 require 'base64'
 require 'logger'
-require 'lib/hwp_properties'
-require 'lib/instance_state'
-require 'lib/documentation'
-require 'lib/base_object'
+
+require 'hwp_properties'
+require 'instance_state'
+require 'documentation'
+require 'base_object'
 
 module DeltaCloud
 
-- 
1.7.2.3


Mime
View raw message