mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Further cleanup add_included.
This commit is contained in:
parent
bae4951e05
commit
c593adbcb2
@ -36,7 +36,7 @@ module ActiveModel
|
|||||||
|
|
||||||
add_links(options)
|
add_links(options)
|
||||||
else
|
else
|
||||||
@hash[:data] = attributes_for(serializer, options)
|
@hash[:data] = resource_objects_for(serializer, options)
|
||||||
relationships = relationships_for(serializer)
|
relationships = relationships_for(serializer)
|
||||||
@hash[:data][:relationships] = relationships if relationships.any?
|
@hash[:data][:relationships] = relationships if relationships.any?
|
||||||
included = included_for(serializer)
|
included = included_for(serializer)
|
||||||
@ -75,15 +75,7 @@ module ActiveModel
|
|||||||
{ id: id.to_s, type: type }
|
{ id: id.to_s, type: type }
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes_for(serializer, options)
|
def resource_object_for(serializer, options = {})
|
||||||
if serializer.respond_to?(:each)
|
|
||||||
serializer.map { |s| resource_object_for(s, options) }
|
|
||||||
else
|
|
||||||
resource_object_for(serializer, options)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def resource_object_for(serializer, options)
|
|
||||||
options[:fields] = @fieldset && @fieldset.fields_for(serializer)
|
options[:fields] = @fieldset && @fieldset.fields_for(serializer)
|
||||||
|
|
||||||
cache_check(serializer) do
|
cache_check(serializer) do
|
||||||
@ -94,6 +86,14 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_objects_for(serializer, options)
|
||||||
|
if serializer.respond_to?(:each)
|
||||||
|
serializer.map { |s| resource_object_for(s, options) }
|
||||||
|
else
|
||||||
|
resource_object_for(serializer, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def relationship_value_for(serializer, options = {})
|
def relationship_value_for(serializer, options = {})
|
||||||
if serializer.respond_to?(:each)
|
if serializer.respond_to?(:each)
|
||||||
serializer.map { |s| resource_identifier_for(s) }
|
serializer.map { |s| resource_identifier_for(s) }
|
||||||
@ -130,10 +130,10 @@ module ActiveModel
|
|||||||
resource_path = [parent, resource_name].compact.join('.')
|
resource_path = [parent, resource_name].compact.join('.')
|
||||||
|
|
||||||
if include_assoc?(resource_path)
|
if include_assoc?(resource_path)
|
||||||
attrs = attributes_for(serializer, @options)
|
resource_object = resource_object_for(serializer, @options)
|
||||||
relationships = relationships_for(serializer)
|
relationships = relationships_for(serializer)
|
||||||
attrs[:relationships] = relationships if relationships.any?
|
resource_object[:relationships] = relationships if relationships.any?
|
||||||
result.push(attrs)
|
result.push(resource_object)
|
||||||
end
|
end
|
||||||
|
|
||||||
if include_nested_assoc?(resource_path)
|
if include_nested_assoc?(resource_path)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user