@@ -29,8 +29,8 @@ module ActiveModel
29
29
# An +attributes+ hash must be defined and should contain any attributes you
30
30
# need to be serialized. Attributes must be strings, not symbols.
31
31
# When called, serializable hash will use instance methods that match the name
32
- # of the attributes hash's keys. In order to override this behavior, take a look
33
- # at the private method +read_attribute_for_serialization+.
32
+ # of the attributes hash's keys. In order to override this behavior, override
33
+ # the +read_attribute_for_serialization+ method .
34
34
#
35
35
# ActiveModel::Serializers::JSON module automatically includes
36
36
# the +ActiveModel::Serialization+ module, so there is no need to
@@ -148,29 +148,29 @@ def serializable_hash(options = nil)
148
148
hash
149
149
end
150
150
151
+ # Hook method defining how an attribute value should be retrieved for
152
+ # serialization. By default this is assumed to be an instance named after
153
+ # the attribute. Override this method in subclasses should you need to
154
+ # retrieve the value for a given attribute differently:
155
+ #
156
+ # class MyClass
157
+ # include ActiveModel::Serialization
158
+ #
159
+ # def initialize(data = {})
160
+ # @data = data
161
+ # end
162
+ #
163
+ # def read_attribute_for_serialization(key)
164
+ # @data[key]
165
+ # end
166
+ # end
167
+ alias :read_attribute_for_serialization :send
168
+
151
169
private
152
170
def attribute_names_for_serialization
153
171
attributes . keys
154
172
end
155
173
156
- # Hook method defining how an attribute value should be retrieved for
157
- # serialization. By default this is assumed to be an instance named after
158
- # the attribute. Override this method in subclasses should you need to
159
- # retrieve the value for a given attribute differently:
160
- #
161
- # class MyClass
162
- # include ActiveModel::Serialization
163
- #
164
- # def initialize(data = {})
165
- # @data = data
166
- # end
167
- #
168
- # def read_attribute_for_serialization(key)
169
- # @data[key]
170
- # end
171
- # end
172
- alias :read_attribute_for_serialization :send
173
-
174
174
def serializable_attributes ( attribute_names )
175
175
attribute_names . index_with { |n | read_attribute_for_serialization ( n ) }
176
176
end
0 commit comments