mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
Remove key from Attribute class.
This commit is contained in:
parent
7d24cbfd3d
commit
a586a45863
@ -1,6 +1,6 @@
|
|||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
Attribute = Struct.new(:name, :key, :block) do
|
Attribute = Struct.new(:name, :block) do
|
||||||
def value(serializer)
|
def value(serializer)
|
||||||
if block
|
if block
|
||||||
serializer.instance_eval(&block)
|
serializer.instance_eval(&block)
|
||||||
|
|||||||
@ -15,9 +15,9 @@ module ActiveModel
|
|||||||
# by the serializer.
|
# by the serializer.
|
||||||
def attributes(requested_attrs = nil, reload = false)
|
def attributes(requested_attrs = nil, reload = false)
|
||||||
@attributes = nil if reload
|
@attributes = nil if reload
|
||||||
@attributes ||= self.class._attributes_data.values.each_with_object({}) do |attr, hash|
|
@attributes ||= self.class._attributes_data.each_with_object({}) do |(key, attr), hash|
|
||||||
next unless requested_attrs.nil? || requested_attrs.include?(attr.key)
|
next unless requested_attrs.nil? || requested_attrs.include?(key)
|
||||||
hash[attr.key] = attr.value(self)
|
hash[key] = attr.value(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -53,14 +53,14 @@ module ActiveModel
|
|||||||
# end
|
# end
|
||||||
def attribute(attr, options = {}, &block)
|
def attribute(attr, options = {}, &block)
|
||||||
key = options.fetch(:key, attr)
|
key = options.fetch(:key, attr)
|
||||||
_attributes_data[attr] = Attribute.new(attr, key, block)
|
_attributes_data[key] = Attribute.new(attr, block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
# keys of attributes
|
# keys of attributes
|
||||||
# @see Serializer::attribute
|
# @see Serializer::attribute
|
||||||
def _attributes
|
def _attributes
|
||||||
_attributes_data.values.map(&:key)
|
_attributes_data.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
@ -68,10 +68,10 @@ module ActiveModel
|
|||||||
# @see Serializer::attribute
|
# @see Serializer::attribute
|
||||||
# @see Adapter::FragmentCache#fragment_serializer
|
# @see Adapter::FragmentCache#fragment_serializer
|
||||||
def _attributes_keys
|
def _attributes_keys
|
||||||
_attributes_data.values
|
_attributes_data
|
||||||
.each_with_object({}) do |attr, hash|
|
.each_with_object({}) do |(key, attr), hash|
|
||||||
next if attr.key == attr.name
|
next if key == attr.name
|
||||||
hash[attr.name] = { key: attr.key }
|
hash[attr.name] = { key: key }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user