Skip to content

Commit

Permalink
Satisfy ruby 1.9.3 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Артём Большаков committed Jul 7, 2015
1 parent e790e7d commit aeb81b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/active_model/serializer/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Serializer
#
# @param [Symbol] name
# @param [ActiveModel::Serializer] serializer
# @param [Hash<Symbol,Object>] options
# @param [Hash{Symbol => Object}] options
#
# @example
# Association.new(:comments, CommentSummarySerializer, embed: :ids)
Expand Down
29 changes: 14 additions & 15 deletions lib/active_model/serializer/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,39 @@ def inherited(base)
base._reflections = self._reflections.try(:dup) || []
end

# @param [Array<Symbol>] names of the association
# @param [Hash<Symbol,Object>] options for given association
# @param [Array(Array<Symbol>, Hash{Symbol => Object})] attrs
# @return [void]
#
# @example
# has_many :comments, serializer: CommentSummarySerializer
# has_many :commits, authors
#
def has_many(*names, **options)
associate names do |name|
def has_many(*attrs)
associate attrs do |name, options|
HasManyReflection.new(name, options)
end
end

# @param [Array<Symbol>] names of the association
# @param [Hash<Symbol,Object>] options for given association
# @param [Array(Array<Symbol>, Hash{Symbol => Object})] attrs
# @return [void]
#
# @example
# belongs_to :author, serializer: AuthorSerializer
#
def belongs_to(*names, **options)
associate names do |name|
def belongs_to(*attrs)
associate attrs do |name, options|
BelongsToReflection.new(name, options)
end
end

# @param [Array<Symbol>] names of the association
# @param [Hash<Symbol,Object>] options for given association
# @param [Array(Array<Symbol>, Hash{Symbol => Object})] attrs
# @return [void]
#
# @example
# has_one :author, serializer: AuthorSerializer
#
def has_one(*names, **options)
associate names do |name|
def has_one(*attrs)
associate attrs do |name, options|
HasOneReflection.new(name, options)
end
end
Expand All @@ -77,17 +74,19 @@ def has_one(*names, **options)
#
# @api private
#
def associate(names)
def associate(attrs)
options = attrs.extract_options!

self._reflections = _reflections.dup

names.each do |name|
attrs.each do |name|
unless method_defined?(name)
define_method name do
object.send name
end
end

self._reflections << yield(name)
self._reflections << yield(name, options)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model/serializer/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Serializer
# build serializer's association by its reflection.
#
# @param [Serializer] subject is a parent serializer for given association
# @param [Hash<Symbol,Object>] parent_serializer_options
# @param [Hash{Symbol => Object}] parent_serializer_options
#
# @example
# # Given the following serializer defined:
Expand Down

0 comments on commit aeb81b2

Please sign in to comment.