aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-05-11 17:17:29 +0100
committerJon Leighton <j@jonathanleighton.com>2012-05-11 20:11:04 +0100
commita8637cf4938d2decd17e702c399ca9c0cf1a6052 (patch)
tree5528c54f422590112a7982a6c1a0188cd66db50b /activemodel/lib/active_model
parentb892b4c08fe2cba133882252c64d123e319eb174 (diff)
downloadrails-a8637cf4938d2decd17e702c399ca9c0cf1a6052.tar.gz
rails-a8637cf4938d2decd17e702c399ca9c0cf1a6052.tar.bz2
rails-a8637cf4938d2decd17e702c399ca9c0cf1a6052.zip
Use respond_to?(:to_ary) rather than is_a?(Enumerable) to detect collection-thing.
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/serialization.rb4
-rw-r--r--activemodel/lib/active_model/serializers/xml.rb4
2 files changed, 5 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb
index 4403ef060b..00cd05b7ef 100644
--- a/activemodel/lib/active_model/serialization.rb
+++ b/activemodel/lib/active_model/serialization.rb
@@ -87,8 +87,8 @@ module ActiveModel
Array(options[:methods]).each { |m| hash[m.to_s] = send(m) if respond_to?(m) }
serializable_add_includes(options) do |association, records, opts|
- hash[association.to_s] = if records.is_a?(Enumerable)
- records.map { |a| a.serializable_hash(opts) }
+ hash[association.to_s] = if records.respond_to?(:to_ary)
+ records.to_ary.map { |a| a.serializable_hash(opts) }
else
records.serializable_hash(opts)
end
diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb
index 5084298210..b78f1ff3f3 100644
--- a/activemodel/lib/active_model/serializers/xml.rb
+++ b/activemodel/lib/active_model/serializers/xml.rb
@@ -115,7 +115,9 @@ module ActiveModel
merged_options = opts.merge(options.slice(:builder, :indent))
merged_options[:skip_instruct] = true
- if records.is_a?(Enumerable)
+ if records.respond_to?(:to_ary)
+ records = records.to_ary
+
tag = ActiveSupport::XmlMini.rename_key(association.to_s, options)
type = options[:skip_types] ? { } : {:type => "array"}
association_name = association.to_s.singularize