@@ -127,19 +127,18 @@ def fragment_cache(cached_hash, non_cached_hash)
127
127
# @api private
128
128
def resource_objects_for ( serializer )
129
129
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 ] )
133
133
else
134
- included . push ( resource )
134
+ included . push ( resource [ :resource_object ] )
135
135
end
136
136
end
137
137
end
138
138
139
139
# 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.
143
142
#
144
143
# @api private
145
144
def _resource_objects_for ( serializer , include_tree , is_primary , hashes = { } )
@@ -152,11 +151,15 @@ def _resource_objects_for(serializer, include_tree, is_primary, hashes = {})
152
151
153
152
key = resource_identifier_for ( serializer )
154
153
if hashes [ key ]
155
- hashes [ key ] [ 1 ] ||= is_primary
154
+ hashes [ key ] [ :is_primary ] ||= is_primary
156
155
return hashes
157
156
end
158
157
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 }
160
163
161
164
serializer . associations ( include_tree ) . each do |association |
162
165
_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 = {})
165
168
hashes
166
169
end
167
170
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
-
178
171
# Get resource type.
179
172
# @return [String] type
180
173
#
0 commit comments