diff options
author | Matthijs Langenberg <mlangenberg@gmail.com> | 2010-09-24 22:37:26 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-27 23:10:55 +0200 |
commit | 67a838574be000f329c0f340474bc9cec1aeca16 (patch) | |
tree | ea3c23a7a5b4df852e5fa041da1c03fc6f42576c /activeresource/lib | |
parent | dd83140b24dcb8a27e226c9de286318a44d7fab1 (diff) | |
download | rails-67a838574be000f329c0f340474bc9cec1aeca16.tar.gz rails-67a838574be000f329c0f340474bc9cec1aeca16.tar.bz2 rails-67a838574be000f329c0f340474bc9cec1aeca16.zip |
Fix broken module namespacing in ActiveResource with Ruby 1.9 [#5699 state:resolved]
Following namespace use case was broken with Ruby 1.9:
class Author < ActiveRecord::Base
...
end
module Api
class Book < ActiveResouce::Base
end
end
Let's say XML contains <book><author><name>John</name></author>....
Api::Book.first.author.class.to_s #=>
Ruby 1.8.7: "Api::Book::Author" (namespaced, correct),
Ruby 1.9: "Author" (toplevel, broken)
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activeresource/lib')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 6135ce4ec1..cd279d890e 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1374,8 +1374,9 @@ module ActiveResource namespaces = module_names[0, module_names.size-1].map do |module_name| receiver = receiver.const_get(module_name) end - if namespace = namespaces.reverse.detect { |ns| ns.const_defined?(resource_name) } - return namespace.const_get(resource_name) + const_args = RUBY_VERSION < "1.9" ? [resource_name] : [resource_name, false] + if namespace = namespaces.reverse.detect { |ns| ns.const_defined?(*const_args) } + return namespace.const_get(*const_args) else raise NameError end @@ -1391,8 +1392,9 @@ module ActiveResource self.class.const_get(resource_name) end rescue NameError - if self.class.const_defined?(resource_name) - resource = self.class.const_get(resource_name) + const_args = RUBY_VERSION < "1.9" ? [resource_name] : [resource_name, false] + if self.class.const_defined?(*const_args) + resource = self.class.const_get(*const_args) else resource = self.class.const_set(resource_name, Class.new(ActiveResource::Base)) end |