Skip to content

Commit a41acec

Browse files
committed
Cleanup.
1 parent 699a287 commit a41acec

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

lib/active_model/serializer/adapter/json_api.rb

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,18 @@ def fragment_cache(cached_hash, non_cached_hash)
127127
# @api private
128128
def resource_objects_for(serializer)
129129
resources = _resource_objects_for(serializer, @include_tree, true).values
130-
resources.each_with_object([[], []]) do |(resource, is_primary), (primary, included)|
131-
if is_primary
132-
primary.push(resource)
130+
resources.each_with_object([[], []]) do |resource, (primary, included)|
131+
if resource[:is_primary]
132+
primary.push(resource[:resource_object])
133133
else
134-
included.push(resource)
134+
included.push(resource[:resource_object])
135135
end
136136
end
137137
end
138138

139139
# Recursively build all requested resource objects and flag them as primary when applicable.
140-
# @return [Hash<ApiObjects::ResourceIdentifierObject, [ApiObjects::ResourceObject, bool]>]
141-
# Hash of pairs of a resource object and a boolean describing whether the corresponding
142-
# resource is primary or included, keyed by resource identifiers.
140+
# @return [Hash<ApiObjects::ResourceIdentifierObject, Hash>]
141+
# Hash of hashes each describing a resource object and whether it is primary or included.
143142
#
144143
# @api private
145144
def _resource_objects_for(serializer, include_tree, is_primary, hashes = {})
@@ -152,11 +151,15 @@ def _resource_objects_for(serializer, include_tree, is_primary, hashes = {})
152151

153152
key = resource_identifier_for(serializer)
154153
if hashes[key]
155-
hashes[key][1] ||= is_primary
154+
hashes[key][:is_primary] ||= is_primary
156155
return hashes
157156
end
158157

159-
hashes[key] = [resource_object_for(serializer), is_primary]
158+
resource_object = ApiObjects::ResourceObject.new(
159+
resource_identifier_for(serializer),
160+
attributes_for(serializer),
161+
relationships_for(serializer))
162+
hashes[key] = { resource_object: resource_object, is_primary: is_primary }
160163

161164
serializer.associations(include_tree).each do |association|
162165
_resource_objects_for(association.serializer, include_tree[association.key], false, hashes)
@@ -165,16 +168,6 @@ def _resource_objects_for(serializer, include_tree, is_primary, hashes = {})
165168
hashes
166169
end
167170

168-
# Transform a serializer into a resource object.
169-
# @return [ApiObjects::ResourceObject] resource object
170-
#
171-
# @api private
172-
def resource_object_for(serializer)
173-
ApiObjects::ResourceObject.new(resource_identifier_for(serializer),
174-
attributes_for(serializer),
175-
relationships_for(serializer))
176-
end
177-
178171
# Get resource type.
179172
# @return [String] type
180173
#

0 commit comments

Comments
 (0)