mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56: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)
|
def self.attributes(*attrs)
|
||||||
attrs = attrs.first if attrs.first.class == Array
|
attrs = attrs.first if attrs.first.class == Array
|
||||||
_attributes.concat(attrs)
|
|
||||||
_attributes.uniq!
|
|
||||||
|
|
||||||
attrs.each do |attr|
|
attrs.each do |attr|
|
||||||
define_method attr do
|
attribute(attr)
|
||||||
object && object.read_attribute_for_serialization(attr)
|
|
||||||
end unless method_defined?(attr) || _fragmented.respond_to?(attr)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.attribute(attr, options = {})
|
def self.attribute(attr, options = {})
|
||||||
key = options.fetch(:key, attr)
|
key = options.fetch(:key, attr)
|
||||||
self._attributes_keys[attr] = { key: key } if key != attr
|
_attributes_keys[attr] = { key: key } if key != attr
|
||||||
self._attributes << key unless _attributes.include?(key)
|
_attributes << key unless _attributes.include?(key)
|
||||||
|
|
||||||
ActiveModelSerializers.silence_warnings do
|
ActiveModelSerializers.silence_warnings do
|
||||||
define_method key do
|
define_method key do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user