You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2010/07/08 12:46:28 UTC
Fixed method rewriting in Ruby client
Hi,
There is a weird issue with Realms in Ruby client code, you can try it
using the Mock driver:
api.realms[0].name => "Europe"
api.realms[1].name => "Europe" / "United States" is expected value here
(api is instance of DeltaCloud::API)
So I replaced 'static method generation' with 'attr_accestor' and
then setting attribute value explicitly.
This works both in Rails and RSpec.
-- Michal
[PATCH core] Fixed method rewriting in client
Posted by mf...@redhat.com.
---
client/lib/deltacloud.rb | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index d65c149..07a62f9 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -199,16 +199,15 @@ module DeltaCloud
end
# Public and private addresses are returned as Array
when "public_addresses", "private_addresses":
- define_method :"#{attribute.name.sanitize}" do
- attribute.xpath('address').collect { |address| address.text }
- end
+ attr_accessor :"#{attribute.name.sanitize}"
+ obj.send(:"#{attribute.name.sanitize}=",
+ attribute.xpath('address').collect { |address| address.text })
# Value for other attributes are just returned using
# method with same name as attribute (eg. .owner_id, .state)
else
- define_method :"#{attribute.name.sanitize}" do
- attribute.text.convert
- end
- logger << "[DC] Added method #{attribute.name} to #{obj.class.name}\n"
+ attr_accessor :"#{attribute.name.sanitize}"
+ obj.send(:"#{attribute.name.sanitize}=", attribute.text.convert)
+ logger << "[DC] Added method #{attribute.name}[#{attribute.text}] to #{obj.class.name}\n"
end
end
end
--
1.7.1