@@ -17,18 +17,8 @@ def serializable_hash(options = nil)
17
17
18
18
private
19
19
20
- def include_directive_from_options ( options )
21
- if options [ :include_directive ]
22
- options [ :include_directive ]
23
- elsif options [ :include ]
24
- JSONAPI ::IncludeDirective . new ( options [ :include ] , allow_wildcard : true )
25
- else
26
- ActiveModelSerializers . default_include_directive
27
- end
28
- end
29
-
30
20
def serializable_hash_for_collection ( serializers , options )
31
- include_directive = include_directive_from_options ( instance_options )
21
+ include_directive = ActiveModel :: Serializer . include_directive_from_options ( instance_options )
32
22
instance_options [ :cached_attributes ] ||= ActiveModel ::Serializer . cache_read_multi ( serializers , self , include_directive )
33
23
instance_opts = instance_options . merge ( include_directive : include_directive )
34
24
serializers . map do |serializer |
@@ -37,37 +27,8 @@ def serializable_hash_for_collection(serializers, options)
37
27
end
38
28
39
29
def serializable_hash_for_single_resource ( serializer , instance_options , options )
40
- options [ :include_directive ] ||= include_directive_from_options ( instance_options )
41
- cached_attributes = instance_options [ :cached_attributes ] ||= { }
42
- resource = serializer . cached_attributes ( options [ :fields ] , cached_attributes , self )
43
- relationships = resource_relationships ( serializer , options )
44
- resource . merge ( relationships )
45
- end
46
-
47
- def resource_relationships ( serializer , options )
48
- relationships = { }
49
- include_directive = options . fetch ( :include_directive )
50
- serializer . associations ( include_directive ) . each do |association |
51
- relationships [ association . key ] ||= relationship_value_for ( association , options )
52
- end
53
-
54
- relationships
55
- end
56
-
57
- def relationship_value_for ( association , options )
58
- return association . options [ :virtual_value ] if association . options [ :virtual_value ]
59
- return unless association . serializer && association . serializer . object
60
-
61
- include_directive = options . fetch ( :include_directive )
62
- opts = instance_options . merge ( include_directive : include_directive [ association . key ] )
63
- relationship_value = Attributes . new ( association . serializer , opts ) . serializable_hash ( options )
64
-
65
- if association . options [ :polymorphic ] && relationship_value
66
- polymorphic_type = association . serializer . object . class . name . underscore
67
- relationship_value = { type : polymorphic_type , polymorphic_type . to_sym => relationship_value }
68
- end
69
-
70
- relationship_value
30
+ options [ :include_directive ] ||= ActiveModel ::Serializer . include_directive_from_options ( instance_options )
31
+ serializer . serializable_hash_for_single_resource ( instance_options , options , self )
71
32
end
72
33
end
73
34
end
0 commit comments