You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2010/12/02 11:15:26 UTC
svn commit: r1041320 - in /incubator/deltacloud/trunk/client:
lib/base_object.rb specs/instances_spec.rb
Author: mfojtik
Date: Thu Dec 2 10:15:26 2010
New Revision: 1041320
URL: http://svn.apache.org/viewvc?rev=1041320&view=rev
Log:
Namespace dynamically generated classes by type.
This resolves an issue where based on the results of one request,
the client will create an Instance class as a subclass of StateFullObject
then, based on the results of another request try to create an Instance
as a subclass of ActionObject, causing a superclass mismatch error.
This patch groups the dynamic classes inside nested containing classes
inside DeltaCloud::API, preventing collisions.
Modified:
incubator/deltacloud/trunk/client/lib/base_object.rb
incubator/deltacloud/trunk/client/specs/instances_spec.rb
Modified: incubator/deltacloud/trunk/client/lib/base_object.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/base_object.rb?rev=1041320&r1=1041319&r2=1041320&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/base_object.rb (original)
+++ incubator/deltacloud/trunk/client/lib/base_object.rb Thu Dec 2 10:15:26 2010
@@ -192,7 +192,7 @@ module DeltaCloud
end
- class StateFullObject < ActionObject
+ class StatefulObject < ActionObject
attr_reader :state
def initialize(opts={}, &block)
@@ -263,25 +263,28 @@ module DeltaCloud
end
def self.add_class(name, parent=:base)
- parent_class = case parent
- when :base then 'BaseObject'
- when :action then 'ActionObject'
- when :state then 'StateFullObject'
- end
+ parent = parent.to_s
+ parent_class = "#{parent.classify}Object"
@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}")
+ class_name = "#{parent.classify}::#{name.classify}"
+ unless @defined_classes.include?(class_name)
+ DeltaCloud::API.class_eval("class #{class_name} < DeltaCloud::#{parent_class}; end")
+ @defined_classes << class_name
end
+
+ DeltaCloud::API.const_get(parent.classify).const_get(name.classify)
end
def self.guess_model_type(response)
response = Nokogiri::XML(response.to_s)
return :action if ((response/'//actions').length == 1) and ((response/'//state').length == 0)
- return :state if ((response/'//actions').length == 1) and ((response/'//state').length == 1)
+ return :stateful if ((response/'//actions').length == 1) and ((response/'//state').length == 1)
return :base
end
+ class API
+ class Action; end
+ class Base; end
+ class Stateful; end
+ end
end
Modified: incubator/deltacloud/trunk/client/specs/instances_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/specs/instances_spec.rb?rev=1041320&r1=1041319&r2=1041320&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/specs/instances_spec.rb (original)
+++ incubator/deltacloud/trunk/client/specs/instances_spec.rb Thu Dec 2 10:15:26 2010
@@ -34,9 +34,9 @@ describe "instances" do
instance.owner_id.should_not be_nil
instance.owner_id.should be_a( String )
instance.image.should_not be_nil
- instance.image.should be_a( DeltaCloud::API::Image )
+ instance.image.should be_a( DeltaCloud::API::Base::Image )
instance.hardware_profile.should_not be_nil
- instance.hardware_profile.should be_a( DeltaCloud::API::HardwareProfile )
+ instance.hardware_profile.should be_a( DeltaCloud::API::Base::HardwareProfile )
instance.state.should_not be_nil
instance.state.should be_a( String )
instance.public_addresses.should_not be_nil