AMS::Associations::Base is now AMS::Association. HasMany and HasOne inherits from it.

This commit is contained in:
Santiago Pastorino 2013-05-16 16:51:56 -07:00
parent 787b7cf24a
commit 055f8fe33c
2 changed files with 69 additions and 71 deletions

View File

@ -152,7 +152,7 @@ module ActiveModel
# with the association name does not exist, the association name is # with the association name does not exist, the association name is
# dispatched to the serialized object. # dispatched to the serialized object.
def has_many(*attrs) def has_many(*attrs)
associate(Associations::HasMany, attrs) associate(Association::HasMany, attrs)
end end
# Defines an association in the object should be rendered. # Defines an association in the object should be rendered.
@ -162,7 +162,7 @@ module ActiveModel
# with the association name does not exist, the association name is # with the association name does not exist, the association name is
# dispatched to the serialized object. # dispatched to the serialized object.
def has_one(*attrs) def has_one(*attrs)
associate(Associations::HasOne, attrs) associate(Association::HasOne, attrs)
end end
# Return a schema hash for the current serializer. This information # Return a schema hash for the current serializer. This information
@ -372,9 +372,9 @@ module ActiveModel
options = klass_options.merge options options = klass_options.merge options
klass klass
elsif value.respond_to?(:to_ary) elsif value.respond_to?(:to_ary)
Associations::HasMany Association::HasMany
else else
Associations::HasOne Association::HasOne
end end
options = default_embed_options.merge!(options) options = default_embed_options.merge!(options)

View File

@ -1,7 +1,6 @@
module ActiveModel module ActiveModel
class Serializer class Serializer
module Associations #:nodoc: class Association #:nodoc:
class Base #:nodoc:
# name: The name of the association. # name: The name of the association.
# #
# options: A hash. These keys are accepted: # options: A hash. These keys are accepted:
@ -71,9 +70,8 @@ module ActiveModel
object object
end end
end end
end
class HasMany < Base #:nodoc: class HasMany < Association #:nodoc:
def root def root
options[:root] || name options[:root] || name
end end
@ -101,7 +99,7 @@ module ActiveModel
end end
end end
class HasOne < Base #:nodoc: class HasOne < Association #:nodoc:
def initialize(name, options={}, serializer_options={}) def initialize(name, options={}, serializer_options={})
super super
@polymorphic = options[:polymorphic] @polymorphic = options[:polymorphic]