Skip to content

Commit

Permalink
Delegate Serializer.attributes to Serializer.attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Sep 18, 2015
1 parent ee40e9f commit 484426c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,16 @@ def self.inherited(base)

def self.attributes(*attrs)
attrs = attrs.first if attrs.first.class == Array
_attributes.concat(attrs)
_attributes.uniq!

attrs.each do |attr|
define_method attr do
object && object.read_attribute_for_serialization(attr)
end unless method_defined?(attr) || _fragmented.respond_to?(attr)
attribute(attr)
end
end

def self.attribute(attr, options = {})
key = options.fetch(:key, attr)
self._attributes_keys[attr] = { key: key } if key != attr
self._attributes << key unless _attributes.include?(key)
_attributes_keys[attr] = { key: key } if key != attr
_attributes << key unless _attributes.include?(key)

ActiveModelSerializers.silence_warnings do
define_method key do
Expand Down

0 comments on commit 484426c

Please sign in to comment.