mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Fix style.
This commit is contained in:
parent
070a2e63bd
commit
f27f13ccc1
@ -14,7 +14,8 @@ module ActiveModel
|
|||||||
@options[:include] = @options[:include].split(',')
|
@options[:include] = @options[:include].split(',')
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields = options.delete(:fields)
|
fields = options.delete(:fields)
|
||||||
|
if fields
|
||||||
@fieldset = ActiveModel::Serializer::Fieldset.new(fields, serializer.json_key)
|
@fieldset = ActiveModel::Serializer::Fieldset.new(fields, serializer.json_key)
|
||||||
else
|
else
|
||||||
@fieldset = options[:fieldset]
|
@fieldset = options[:fieldset]
|
||||||
@ -48,7 +49,7 @@ module ActiveModel
|
|||||||
|
|
||||||
def fragment_cache(cached_hash, non_cached_hash)
|
def fragment_cache(cached_hash, non_cached_hash)
|
||||||
root = false if @options.include?(:include)
|
root = false if @options.include?(:include)
|
||||||
JsonApi::FragmentCache.new().fragment_cache(root, cached_hash, non_cached_hash)
|
JsonApi::FragmentCache.new.fragment_cache(root, cached_hash, non_cached_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -103,8 +104,6 @@ module ActiveModel
|
|||||||
options[:virtual_value]
|
options[:virtual_value]
|
||||||
elsif serializer && serializer.object
|
elsif serializer && serializer.object
|
||||||
resource_identifier_for(serializer)
|
resource_identifier_for(serializer)
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -121,8 +120,8 @@ module ActiveModel
|
|||||||
if serializer.respond_to?(:each)
|
if serializer.respond_to?(:each)
|
||||||
serializer.flat_map { |s| _included_for(resource_name, s, parent) }.uniq
|
serializer.flat_map { |s| _included_for(resource_name, s, parent) }.uniq
|
||||||
else
|
else
|
||||||
|
return [] unless serializer && serializer.object
|
||||||
result = []
|
result = []
|
||||||
if serializer && serializer.object
|
|
||||||
resource_path = [parent, resource_name].compact.join('.')
|
resource_path = [parent, resource_name].compact.join('.')
|
||||||
|
|
||||||
if include_assoc?(resource_path)
|
if include_assoc?(resource_path)
|
||||||
@ -133,14 +132,13 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
if include_nested_assoc?(resource_path)
|
if include_nested_assoc?(resource_path)
|
||||||
serializer.associations.each do |association|
|
non_empty_associations = serializer.associations.select(&:serializer)
|
||||||
if association.serializer
|
|
||||||
|
non_empty_associations.each do |association|
|
||||||
result.concat(_included_for(association.key, association.serializer, resource_path))
|
result.concat(_included_for(association.key, association.serializer, resource_path))
|
||||||
result.uniq!
|
result.uniq!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -160,9 +158,7 @@ module ActiveModel
|
|||||||
def add_links(options)
|
def add_links(options)
|
||||||
links = @hash.fetch(:links) { {} }
|
links = @hash.fetch(:links) { {} }
|
||||||
collection = serializer.object
|
collection = serializer.object
|
||||||
if is_paginated?(collection)
|
@hash[:links] = add_pagination_links(links, collection, options) if paginated?(collection)
|
||||||
@hash[:links] = add_pagination_links(links, collection, options)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_pagination_links(links, collection, options)
|
def add_pagination_links(links, collection, options)
|
||||||
@ -170,7 +166,7 @@ module ActiveModel
|
|||||||
links.update(pagination_links)
|
links.update(pagination_links)
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_paginated?(collection)
|
def paginated?(collection)
|
||||||
collection.respond_to?(:current_page) &&
|
collection.respond_to?(:current_page) &&
|
||||||
collection.respond_to?(:total_pages) &&
|
collection.respond_to?(:total_pages) &&
|
||||||
collection.respond_to?(:size)
|
collection.respond_to?(:size)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user