Move attributes cache method out of concern

This commit is contained in:
Benjamin Fleischer
2017-03-31 13:09:51 -05:00
parent 6b1a487e00
commit c2dccbac5f
2 changed files with 20 additions and 17 deletions

View File

@@ -379,8 +379,7 @@ module ActiveModel
def serializable_hash(adapter_options = nil, options = {}, adapter_instance = self.class.serialization_adapter_instance)
adapter_options ||= {}
options[:include_directive] ||= ActiveModel::Serializer.include_directive_from_options(adapter_options)
cached_attributes = adapter_options[:cached_attributes] ||= {}
resource = fetch_attributes(options[:fields], cached_attributes, adapter_instance)
resource = attributes_hash(adapter_options, options, adapter_instance)
relationships = resource_relationships(adapter_options, options, adapter_instance)
resource.merge(relationships)
end
@@ -412,6 +411,17 @@ module ActiveModel
end
end
# @api private
def attributes_hash(_adapter_options, options, adapter_instance)
if self.class.cache_enabled?
fetch_attributes(options[:fields], options[:cached_attributes] || {}, adapter_instance)
elsif self.class.fragment_cache_enabled?
fetch_attributes_fragment(adapter_instance, options[:cached_attributes] || {})
else
attributes(options[:fields], true)
end
end
# @api private
def resource_relationships(adapter_options, options, adapter_instance)
relationships = {}