aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash/conversions.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-09 23:35:43 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-09 23:35:43 +0000
commit0c6d1785529ab2f9c86908f03a10c871512311e5 (patch)
tree544d3d4ad3aa218db856941aa581ab17352fb498 /activesupport/lib/active_support/core_ext/hash/conversions.rb
parentd872281975b2bdcfcd06e21b55d78c8fb53ba5d1 (diff)
downloadrails-0c6d1785529ab2f9c86908f03a10c871512311e5.tar.gz
rails-0c6d1785529ab2f9c86908f03a10c871512311e5.tar.bz2
rails-0c6d1785529ab2f9c86908f03a10c871512311e5.zip
Implemented nested to_xml and named elements for array xmling [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3830 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index 584a7ec7cc..bbbda3698f 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -24,15 +24,18 @@ module ActiveSupport #:nodoc:
for key in keys
value = self[key]
- if value.is_a?(self.class)
- value.to_xml(options.merge({ :root => key, :skip_instruct => true }))
- else
- type_name = XML_TYPE_NAMES[value.class.to_s]
+ case value.class.to_s # TODO: Figure out why I have to to_s the class to do comparisons in order for tests to run
+ when "Hash"
+ value.to_xml(options.merge({ :root => key, :skip_instruct => true }))
+ when "Array"
+ value.to_xml(options.merge({ :root => key, :children => key.to_s.singularize, :skip_instruct => true}))
+ else
+ type_name = XML_TYPE_NAMES[value.class.to_s]
- options[:builder].__send__(key.to_s.dasherize,
- XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value,
- options[:skip_types] || value.nil? || type_name.nil? ? { } : { :type => type_name }
- )
+ options[:builder].__send__(key.to_s.dasherize,
+ XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value,
+ options[:skip_types] || value.nil? || type_name.nil? ? { } : { :type => type_name }
+ )
end
end
end