Skip to content

Commit a586a45

Browse files
committed
Remove key from Attribute class.
1 parent 7d24cbf commit a586a45

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/active_model/serializer/attribute.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ActiveModel
22
class Serializer
3-
Attribute = Struct.new(:name, :key, :block) do
3+
Attribute = Struct.new(:name, :block) do
44
def value(serializer)
55
if block
66
serializer.instance_eval(&block)

lib/active_model/serializer/attributes.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ module Attributes
1515
# by the serializer.
1616
def attributes(requested_attrs = nil, reload = false)
1717
@attributes = nil if reload
18-
@attributes ||= self.class._attributes_data.values.each_with_object({}) do |attr, hash|
19-
next unless requested_attrs.nil? || requested_attrs.include?(attr.key)
20-
hash[attr.key] = attr.value(self)
18+
@attributes ||= self.class._attributes_data.each_with_object({}) do |(key, attr), hash|
19+
next unless requested_attrs.nil? || requested_attrs.include?(key)
20+
hash[key] = attr.value(self)
2121
end
2222
end
2323
end
@@ -53,25 +53,25 @@ def attributes(*attrs)
5353
# end
5454
def attribute(attr, options = {}, &block)
5555
key = options.fetch(:key, attr)
56-
_attributes_data[attr] = Attribute.new(attr, key, block)
56+
_attributes_data[key] = Attribute.new(attr, block)
5757
end
5858

5959
# @api private
6060
# keys of attributes
6161
# @see Serializer::attribute
6262
def _attributes
63-
_attributes_data.values.map(&:key)
63+
_attributes_data.keys
6464
end
6565

6666
# @api private
6767
# maps attribute value to explict key name
6868
# @see Serializer::attribute
6969
# @see Adapter::FragmentCache#fragment_serializer
7070
def _attributes_keys
71-
_attributes_data.values
72-
.each_with_object({}) do |attr, hash|
73-
next if attr.key == attr.name
74-
hash[attr.name] = { key: attr.key }
71+
_attributes_data
72+
.each_with_object({}) do |(key, attr), hash|
73+
next if key == attr.name
74+
hash[attr.name] = { key: key }
7575
end
7676
end
7777
end

0 commit comments

Comments
 (0)