@@ -10,42 +10,16 @@ def serializable_hash(options = nil)
10
10
options = serialization_options ( options )
11
11
12
12
if serializer . respond_to? ( :each )
13
- serializable_hash_for_collection ( options )
13
+ serializer . map do |element |
14
+ element . serialize ( options , instance_options , self , @include_tree )
15
+ end
14
16
else
15
- serializable_hash_for_single_resource ( options )
17
+ serializer . serialize ( options , instance_options , self , @include_tree )
16
18
end
17
19
end
18
20
19
21
private
20
22
21
- def serializable_hash_for_collection ( options )
22
- instance_options [ :cached_attributes ] ||= ActiveModel ::Serializer . cache_read_multi ( serializer , self , @include_tree )
23
- serializer . map { |s | Attributes . new ( s , instance_options ) . serializable_hash ( options ) }
24
- end
25
-
26
- def serializable_hash_for_single_resource ( options )
27
- resource = serializer . cached_attributes ( options [ :fields ] , self )
28
- relationships = resource_relationships ( options )
29
- resource . merge ( relationships )
30
- end
31
-
32
- def resource_relationships ( options )
33
- relationships = { }
34
- serializer . associations ( @include_tree ) . each do |association |
35
- relationships [ association . key ] = relationship_value_for ( association , options )
36
- end
37
-
38
- relationships
39
- end
40
-
41
- def relationship_value_for ( association , options )
42
- return association . options [ :virtual_value ] if association . options [ :virtual_value ]
43
- return unless association . serializer && association . serializer . object
44
-
45
- opts = instance_options . merge ( include : @include_tree [ association . key ] )
46
- Attributes . new ( association . serializer , opts ) . serializable_hash ( options )
47
- end
48
-
49
23
# no-op: Attributes adapter does not include meta data, because it does not support root.
50
24
def include_meta ( json )
51
25
json
0 commit comments