Fix style.

This commit is contained in:
Lucas Hosseini 2015-09-06 19:18:36 +02:00
parent 070a2e63bd
commit f27f13ccc1

View File

@ -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,14 +104,12 @@ 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
def relationships_for(serializer) def relationships_for(serializer)
Hash[serializer.associations.map { |association| [ association.key, { data: relationship_value_for(association.serializer, association.options) } ] }] Hash[serializer.associations.map { |association| [association.key, { data: relationship_value_for(association.serializer, association.options) }] }]
end end
def included_for(serializer) def included_for(serializer)
@ -121,24 +120,23 @@ 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)
primary_data = primary_data_for(serializer, @options) primary_data = primary_data_for(serializer, @options)
relationships = relationships_for(serializer) relationships = relationships_for(serializer)
primary_data[:relationships] = relationships if relationships.any? primary_data[:relationships] = relationships if relationships.any?
result.push(primary_data) result.push(primary_data)
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
result.concat(_included_for(association.key, association.serializer, resource_path)) non_empty_associations.each do |association|
result.uniq! result.concat(_included_for(association.key, association.serializer, resource_path))
end result.uniq!
end
end end
end end
result result
@ -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)