mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
* Make assocations asserts easier to understand * Refactor Association into Field like everything else * Make assocation serializer/links/meta lazier * Push association deeper into relationship * Simplify association usage in relationships * Better naming of reflection parent serializer * Easier to read association method
35 lines
710 B
Ruby
35 lines
710 B
Ruby
module ActiveModel
|
|
class Serializer
|
|
# This class hold all information about serializer's association.
|
|
#
|
|
# @attr [Symbol] name
|
|
# @attr [Hash{Symbol => Object}] options
|
|
# @attr [block]
|
|
#
|
|
# @example
|
|
# Association.new(:comments, { serializer: CommentSummarySerializer })
|
|
#
|
|
class Association < Field
|
|
# @return [Symbol]
|
|
def key
|
|
options.fetch(:key, name)
|
|
end
|
|
|
|
# @return [ActiveModel::Serializer, nil]
|
|
def serializer
|
|
options[:serializer]
|
|
end
|
|
|
|
# @return [Hash]
|
|
def links
|
|
options.fetch(:links) || {}
|
|
end
|
|
|
|
# @return [Hash, nil]
|
|
def meta
|
|
options[:meta]
|
|
end
|
|
end
|
|
end
|
|
end
|