From 9e4461438f8ce584b635aca35579c36537a340ca Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 21 Jun 2007 15:07:15 +0000 Subject: Added proper handling of arrays. Closes #8537 [hasmanyjosh] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7074 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_support/core_ext/array/conversions.rb | 13 +++++++++---- .../lib/active_support/core_ext/hash/conversions.rb | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index a4d056e81c..426e53ea1c 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -63,10 +63,15 @@ module ActiveSupport #:nodoc: opts = options.merge({ :root => children }) - options[:builder].tag!(root) { - yield options[:builder] if block_given? - each { |e| e.to_xml(opts.merge!({ :skip_instruct => true })) } - } + xml = options[:builder] + if empty? + xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) + else + xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) { + yield xml if block_given? + each { |e| e.to_xml(opts.merge!({ :skip_instruct => true })) } + } + end end end diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 2334bb671b..2cccd9c30e 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -163,6 +163,20 @@ module ActiveSupport #:nodoc: else content end + elsif value['type'] == 'array' + child_key, entries = value.detect { |k,v| k != 'type' } # child_key is throwaway + if entries.nil? + [] + else + case entries.class.to_s # something weird with classes not matching here. maybe singleton methods breaking is_a? + when "Array" + entries.collect { |v| typecast_xml_value(v) } + when "Hash" + [typecast_xml_value(entries)] + else + raise "can't typecast #{entries.inspect}" + end + end elsif value['type'] == 'string' && value['nil'] != 'true' "" else -- cgit v1.2.3