mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Improve comments; move caching concern to caching.rb
This commit is contained in:
parent
36b4eac79b
commit
2e71bc47f4
@ -108,8 +108,8 @@ module ActiveModel
|
||||
@serialization_adapter_instance ||= ActiveModelSerializers::Adapter::Attributes
|
||||
end
|
||||
|
||||
# Configuration options may also be set in
|
||||
# Serializers and Adapters
|
||||
# Preferred interface is ActiveModelSerializers.config
|
||||
# BEGIN DEFAULT CONFIGURATION
|
||||
config.collection_serializer = ActiveModel::Serializer::CollectionSerializer
|
||||
config.serializer_lookup_enabled = true
|
||||
|
||||
@ -159,6 +159,7 @@ module ActiveModel
|
||||
config.serializer_lookup_chain = ActiveModelSerializers::LookupChain::DEFAULT.dup
|
||||
|
||||
config.schema_path = 'test/support/schemas'
|
||||
# END DEFAULT CONFIGURATION
|
||||
|
||||
with_options instance_writer: false, instance_reader: false do |serializer|
|
||||
serializer.class_attribute :_attributes_data # @api private
|
||||
@ -180,12 +181,14 @@ module ActiveModel
|
||||
base._links = _links.dup
|
||||
end
|
||||
|
||||
# keys of attributes
|
||||
# @return [Array<Symbol>] Key names of declared attributes
|
||||
# @see Serializer::attribute
|
||||
def self._attributes
|
||||
_attributes_data.keys
|
||||
end
|
||||
|
||||
# BEGIN SERIALIZER MACROS
|
||||
|
||||
# @example
|
||||
# class AdminAuthorSerializer < ActiveModel::Serializer
|
||||
# attributes :id, :name, :recent_edits
|
||||
@ -214,18 +217,6 @@ module ActiveModel
|
||||
_attributes_data[key] = Attribute.new(attr, options, block)
|
||||
end
|
||||
|
||||
# @api private
|
||||
# maps attribute value to explicit key name
|
||||
# @see Serializer::attribute
|
||||
# @see ActiveModel::Serializer::Caching#fragmented_attributes
|
||||
def self._attributes_keys
|
||||
_attributes_data
|
||||
.each_with_object({}) do |(key, attr), hash|
|
||||
next if key == attr.name
|
||||
hash[attr.name] = { key: key }
|
||||
end
|
||||
end
|
||||
|
||||
# @param [Symbol] name of the association
|
||||
# @param [Hash<Symbol => any>] options for the reflection
|
||||
# @return [void]
|
||||
@ -302,6 +293,8 @@ module ActiveModel
|
||||
self._type = type && type.to_s
|
||||
end
|
||||
|
||||
# END SERIALIZER MACROS
|
||||
|
||||
attr_accessor :object, :root, :scope
|
||||
|
||||
# `scope_name` is set as :current_user by default in the controller.
|
||||
|
||||
@ -68,6 +68,18 @@ module ActiveModel
|
||||
_cache_options && _cache_options[:skip_digest]
|
||||
end
|
||||
|
||||
# @api private
|
||||
# maps attribute value to explicit key name
|
||||
# @see Serializer::attribute
|
||||
# @see Serializer::fragmented_attributes
|
||||
def _attributes_keys
|
||||
_attributes_data
|
||||
.each_with_object({}) do |(key, attr), hash|
|
||||
next if key == attr.name
|
||||
hash[attr.name] = { key: key }
|
||||
end
|
||||
end
|
||||
|
||||
def fragmented_attributes
|
||||
cached = _cache_only ? _cache_only : _attributes - _cache_except
|
||||
cached = cached.map! { |field| _attributes_keys.fetch(field, field) }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user