Rename attribute with :key (0.8.x compatibility)

This commit is contained in:
Gary Gordon
2014-11-06 11:10:15 -05:00
parent ac37570bff
commit 08716d20c9
4 changed files with 48 additions and 1 deletions

View File

@@ -21,7 +21,6 @@ module ActiveModel
def self.attributes(*attrs)
@_attributes.concat attrs
attrs.each do |attr|
define_method attr do
object.read_attribute_for_serialization(attr)
@@ -29,6 +28,14 @@ module ActiveModel
end
end
def self.attribute(attr, options = {})
key = options.fetch(:key, attr)
@_attributes.concat [key]
define_method key do
object.read_attribute_for_serialization(attr)
end unless method_defined?(key)
end
# Defines an association in the object should be rendered.
#
# The serializer object should implement the association name