@@ -7,42 +7,39 @@ def initialize(serializer, options = {})
77 @include_tree = IncludeTree . from_include_args ( options [ :include ] || '*' )
88 end
99
10+ def serializable_hash_for_collection ( options )
11+ serializer . map { |s | Attributes . new ( s , instance_options ) . serializable_hash ( options ) }
12+ end
13+
14+ def serializable_hash_for_single_resource ( options )
15+ hash = { }
16+
17+ core = cache_check ( serializer ) do
18+ serializer . attributes ( options )
19+ end
20+
21+ serializer . associations ( @include_tree ) . each do |association |
22+ hash [ association . key ] =
23+ if association . options [ :virtual_value ]
24+ association . options [ :virtual_value ]
25+ elsif association . serializer && association . serializer . object
26+ Attributes . new ( association . serializer , association . options . merge ( include : @include_tree [ association . key ] ) )
27+ . serializable_hash ( options )
28+ end
29+ end
30+ result = core . merge hash
31+
32+ result
33+ end
34+
1035 def serializable_hash ( options = nil )
1136 options ||= { }
37+
1238 if serializer . respond_to? ( :each )
13- result = serializer . map { | s | Attributes . new ( s , instance_options ) . serializable_hash ( options ) }
39+ serializable_hash_for_collection ( options )
1440 else
15- hash = { }
16-
17- core = cache_check ( serializer ) do
18- serializer . attributes ( options )
19- end
20-
21- serializer . associations ( @include_tree ) . each do |association |
22- serializer = association . serializer
23- association_options = association . options
24-
25- if serializer . respond_to? ( :each )
26- array_serializer = serializer
27- hash [ association . key ] = array_serializer . map do |item |
28- cache_check ( item ) do
29- item . attributes ( association_options )
30- end
31- end
32- else
33- hash [ association . key ] =
34- if serializer && serializer . object
35- cache_check ( serializer ) do
36- serializer . attributes ( options )
37- end
38- elsif association_options [ :virtual_value ]
39- association_options [ :virtual_value ]
40- end
41- end
42- end
43- result = core . merge hash
41+ serializable_hash_for_single_resource ( options )
4442 end
45- result
4643 end
4744
4845 def fragment_cache ( cached_hash , non_cached_hash )
0 commit comments