File tree Expand file tree Collapse file tree 2 files changed +4
-10
lines changed
lib/active_model/serializer Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -44,13 +44,7 @@ def object
44
44
def initialize ( serializer , options = { } )
45
45
super
46
46
@include_tree = IncludeTree . from_include_args ( options [ :include ] )
47
-
48
- fields = options . delete ( :fields )
49
- if fields
50
- @fieldset = ActiveModel ::Serializer ::Fieldset . new ( fields )
51
- else
52
- @fieldset = options [ :fieldset ]
53
- end
47
+ @fieldset = options [ :fieldset ] || ActiveModel ::Serializer ::Fieldset . new ( options . delete ( :fields ) )
54
48
end
55
49
56
50
def serializable_hash ( options = nil )
@@ -175,7 +169,7 @@ def relationship_value_for(serializer, options = {})
175
169
176
170
def relationships_for ( serializer )
177
171
resource_type = resource_identifier_type_for ( serializer )
178
- requested_associations = fieldset . try ( : fields_for, resource_type ) || '*'
172
+ requested_associations = fieldset . fields_for ( resource_type ) || '*'
179
173
include_tree = IncludeTree . from_include_args ( requested_associations )
180
174
serializer . associations ( include_tree ) . each_with_object ( { } ) do |association , hash |
181
175
hash [ association . key ] = { data : relationship_value_for ( association . serializer , association . options ) }
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ module ActiveModel
2
2
class Serializer
3
3
class Fieldset
4
4
def initialize ( fields )
5
- @raw_fields = fields
5
+ @raw_fields = fields || { }
6
6
end
7
7
8
8
def fields
@@ -21,7 +21,7 @@ def fields_for(type)
21
21
22
22
def parsed_fields
23
23
if raw_fields . is_a? ( Hash )
24
- raw_fields . inject ( { } ) { |h , ( k , v ) | h [ k . to_sym ] = v . map ( &:to_sym ) ; h }
24
+ raw_fields . each_with_object ( { } ) { |( k , v ) , h | h [ k . to_sym ] = v . map ( &:to_sym ) }
25
25
else
26
26
{ }
27
27
end
You can’t perform that action at this time.
0 commit comments