@@ -22,14 +22,24 @@ def inherited(base)
2222 base . _reflections = self . _reflections . try ( :dup ) || [ ]
2323 end
2424
25+ # alias_method :reflections, :_reflections
26+
2527 # Defines an association in the object should be rendered.
2628 #
2729 # The serializer object should implement the association name
2830 # as a method which should return an array when invoked. If a method
2931 # with the association name does not exist, the association name is
3032 # dispatched to the serialized object.
31- def has_many ( *attrs )
32- associate attrs do |name , options |
33+ #
34+ # @param [Array<Symbol>] names association names
35+ # @param [Hash<Symbol,Object>] options for given association
36+ #
37+ # @example
38+ # has_many :comments, serializer: CommentSummarySerializer
39+ # has_many :commits, authors
40+ #
41+ def has_many ( *names , **options )
42+ associate names do |name |
3343 HasManyReflection . new ( name , options )
3444 end
3545 end
@@ -40,8 +50,8 @@ def has_many(*attrs)
4050 # as a method which should return an object when invoked. If a method
4151 # with the association name does not exist, the association name is
4252 # dispatched to the serialized object.
43- def belongs_to ( *attrs )
44- associate attrs do |name , options |
53+ def belongs_to ( *names , ** options )
54+ associate names do |name |
4555 BelongsToReflection . new ( name , options )
4656 end
4757 end
@@ -52,26 +62,25 @@ def belongs_to(*attrs)
5262 # as a method which should return an object when invoked. If a method
5363 # with the association name does not exist, the association name is
5464 # dispatched to the serialized object.
55- def has_one ( *attrs )
56- associate attrs do |name , options |
65+ def has_one ( *names , ** options )
66+ associate names do |name |
5767 HasOneReflection . new ( name , options )
5868 end
5969 end
6070
6171 private
6272
63- def associate ( attrs , &block ) #:nodoc:
64- options = attrs . extract_options!
73+ def associate ( names , &block ) #:nodoc:
6574 self . _reflections = _reflections . dup
6675
67- attrs . each do |name |
76+ names . each do |name |
6877 unless method_defined? ( name )
6978 define_method name do
7079 object . send name
7180 end
7281 end
7382
74- self . _reflections << block . call ( name , options )
83+ self . _reflections << block . call ( name )
7584 end
7685 end
7786 end
0 commit comments