File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -39,17 +39,19 @@ def use_adapter?
39
39
options . partition { |k , _ | ADAPTER_OPTION_KEYS . include? k } . map { |h | Hash [ h ] }
40
40
41
41
if use_adapter? && ( serializer = get_serializer ( resource ) )
42
-
43
42
@_serializer_opts [ :scope ] ||= serialization_scope
44
43
@_serializer_opts [ :scope_name ] = _serialization_scope
45
44
46
- # omg hax
47
- object = serializer . new ( resource , @_serializer_opts )
48
- adapter = ActiveModel ::Serializer ::Adapter . create ( object , @_adapter_opts )
49
- super ( adapter , options )
50
- else
51
- super ( resource , options )
45
+ object = serializer . new ( resource , @_serializer_opts )
46
+
47
+ if serializer == ActiveModel ::Serializer . config . array_serializer
48
+ resource = ActiveModel ::Serializer ::Adapter . create ( object , @_adapter_opts ) unless object . objects . all? { |i | i . nil? }
49
+ else
50
+ resource = ActiveModel ::Serializer ::Adapter . create ( object , @_adapter_opts )
51
+ end
52
52
end
53
+
54
+ super ( resource , options )
53
55
end
54
56
end
55
57
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ class ArraySerializer
4
4
include Enumerable
5
5
delegate :each , to : :@objects
6
6
7
- attr_reader :meta , :meta_key
7
+ attr_reader :meta , :meta_key , :objects
8
8
9
9
def initialize ( objects , options = { } )
10
10
@resource = objects
@@ -13,7 +13,10 @@ def initialize(objects, options = {})
13
13
:serializer ,
14
14
ActiveModel ::Serializer . serializer_for ( object )
15
15
)
16
- serializer_class . new ( object , options . except ( :serializer ) )
16
+
17
+ unless serializer_class . nil?
18
+ serializer_class . new ( object , options . except ( :serializer ) )
19
+ end
17
20
end
18
21
@meta = options [ :meta ]
19
22
@meta_key = options [ :meta_key ]
You can’t perform that action at this time.
0 commit comments