Separate associations into multiple files

This commit is contained in:
Pol Miro
2014-08-24 15:28:20 -07:00
parent bb18fc6225
commit e8b983490e
4 changed files with 61 additions and 49 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