@@ -27,12 +27,12 @@ class Serializer
27
27
)
28
28
/x
29
29
30
- class << self
31
- attr_accessor :_attributes
32
- attr_accessor :_attributes_keys
33
- end
34
-
35
30
with_options instance_writer : false , instance_reader : false do |serializer |
31
+ class_attribute :_type , instance_reader : true
32
+ class_attribute :_attributes
33
+ self . _attributes ||= [ ]
34
+ class_attribute :_attributes_keys
35
+ self . _attributes_keys ||= { }
36
36
serializer . class_attribute :_cache
37
37
serializer . class_attribute :_fragmented
38
38
serializer . class_attribute :_cache_key
@@ -43,8 +43,8 @@ class << self
43
43
end
44
44
45
45
def self . inherited ( base )
46
- base . _attributes = _attributes . try ( : dup) || [ ]
47
- base . _attributes_keys = _attributes_keys . try ( : dup) || { }
46
+ base . _attributes = _attributes . dup
47
+ base . _attributes_keys = _attributes_keys . dup
48
48
base . _cache_digest = digest_caller_file ( caller . first )
49
49
super
50
50
end
@@ -125,7 +125,6 @@ def self.get_serializer_for(klass)
125
125
end
126
126
127
127
attr_accessor :object , :root , :scope
128
- class_attribute :_type , instance_writer : false
129
128
130
129
def initialize ( object , options = { } )
131
130
self . object = object
@@ -149,10 +148,10 @@ def attributes
149
148
attributes = self . class . _attributes . dup
150
149
151
150
attributes . each_with_object ( { } ) do |name , hash |
152
- unless self . class . _fragmented
153
- hash [ name ] = send ( name )
154
- else
151
+ if self . class . _fragmented
155
152
hash [ name ] = self . class . _fragmented . public_send ( name )
153
+ else
154
+ hash [ name ] = send ( name )
156
155
end
157
156
end
158
157
end
0 commit comments