mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #1167 from rails-api/simplify_serializer_attributes
Delegate Serializer.attributes to Serializer.attribute
This commit is contained in:
commit
e0a0ad3e46
@ -50,20 +50,16 @@ module ActiveModel
|
||||
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user