sync with upstream

This commit is contained in:
Theodore Konukhov
2014-08-29 06:28:13 +02:00
10 changed files with 584 additions and 65 deletions

View File

@@ -0,0 +1,36 @@
module ActiveModel
class Serializer
class Association
class HasMany < Association
def initialize(name, *args)
super
@root_key = @embedded_key
@key ||= "#{name.to_s.singularize}_ids"
end
def serializer_class(object, _)
if use_array_serializer?
ArraySerializer
else
serializer_from_options
end
end
def options
if use_array_serializer?
{ each_serializer: serializer_from_options }.merge! super
else
super
end
end
private
def use_array_serializer?
!serializer_from_options ||
serializer_from_options && !(serializer_from_options <= ArraySerializer)
end
end
end
end
end