diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-12-12 15:29:54 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-12-12 15:29:54 +0000 |
commit | 55d4dbb8df9b4e6e46d461352f97e35ba69b417e (patch) | |
tree | 399c3929848e39f21f5770a9e11e5138407ea745 /activeresource/lib/active_resource/connection.rb | |
parent | 2f5ee5a812bee922b198c7efbe3ffff29d072ffd (diff) | |
download | rails-55d4dbb8df9b4e6e46d461352f97e35ba69b417e.tar.gz rails-55d4dbb8df9b4e6e46d461352f97e35ba69b417e.tar.bz2 rails-55d4dbb8df9b4e6e46d461352f97e35ba69b417e.zip |
Fix issues with ActiveResource collection handling. Closes #6291. [bmilekic]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5714 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/lib/active_resource/connection.rb')
-rw-r--r-- | activeresource/lib/active_resource/connection.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index e4f733cf70..c52d4d4839 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -49,7 +49,7 @@ module ActiveResource end def get(path) - Hash.from_xml(request(:get, path, build_request_headers).body) + from_xml_data(Hash.from_xml(request(:get, path, build_request_headers).body).values.first) end def delete(path) @@ -113,5 +113,25 @@ module ActiveResource def logger ActiveResource::Base.logger end + + # Manipulate from_xml Hash, because xml_simple is not exactly what we + # want for ActiveResource. + def from_xml_data(data) + case data + when Hash + if data.keys.size == 1 + case data.values.first + when Hash then [ from_xml_data(data.values.first) ] + when Array then from_xml_data(data.values.first) + else data + end + else + data.each_key { |key| data[key] = from_xml_data(data[key]) } + data + end + when Array then data.collect { |val| from_xml_data(val) } + else data + end + end end end |