Simplify Serializer#cached_attributes to take a fields argument

This commit is contained in:
Benjamin Fleischer 2016-04-14 22:53:06 -05:00
parent ba23de686d
commit 385abb4ba0
2 changed files with 4 additions and 4 deletions

View File

@ -208,17 +208,17 @@ module ActiveModel
end
end
def cached_attributes(options, cached_attributes, adapter_instance)
def cached_attributes(fields, cached_attributes, adapter_instance)
if self.class.cache_enabled?
key = cache_key(adapter_instance)
cached_attributes.fetch(key) do
cache_check(adapter_instance) do
attributes(options[:fields])
attributes(fields)
end
end
else
cache_check(adapter_instance) do
attributes(options[:fields])
attributes(fields)
end
end
end

View File

@ -33,7 +33,7 @@ module ActiveModelSerializers
def serializable_hash_for_single_resource(options)
cached_attributes = instance_options[:cached_attributes] || {}
resource = serializer.cached_attributes(options, cached_attributes, self)
resource = serializer.cached_attributes(options[:fields], cached_attributes, self)
relationships = resource_relationships(options)
resource.merge(relationships)
end