From d39aec205104bdaedb6dbc7f79303ff3020c3f62 Mon Sep 17 00:00:00 2001 From: Lucas Hosseini Date: Tue, 29 Dec 2015 22:45:41 +0100 Subject: [PATCH] Remove `key` from `Attribute` class. --- lib/active_model/serializer/attribute.rb | 2 +- lib/active_model/serializer/attributes.rb | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/active_model/serializer/attribute.rb b/lib/active_model/serializer/attribute.rb index 0ab0a37bb..5c9893ca5 100644 --- a/lib/active_model/serializer/attribute.rb +++ b/lib/active_model/serializer/attribute.rb @@ -1,6 +1,6 @@ module ActiveModel class Serializer - Attribute = Struct.new(:name, :key, :block) do + Attribute = Struct.new(:name, :block) do def value(serializer) if block serializer.instance_eval(&block) diff --git a/lib/active_model/serializer/attributes.rb b/lib/active_model/serializer/attributes.rb index c70184397..8109d2e76 100644 --- a/lib/active_model/serializer/attributes.rb +++ b/lib/active_model/serializer/attributes.rb @@ -15,9 +15,9 @@ module Attributes # by the serializer. def attributes(requested_attrs = nil, reload = false) @attributes = nil if reload - @attributes ||= self.class._attributes_data.values.each_with_object({}) do |attr, hash| - next unless requested_attrs.nil? || requested_attrs.include?(attr.key) - hash[attr.key] = attr.value(self) + @attributes ||= self.class._attributes_data.each_with_object({}) do |(key, attr), hash| + next unless requested_attrs.nil? || requested_attrs.include?(key) + hash[key] = attr.value(self) end end end @@ -53,14 +53,14 @@ def attributes(*attrs) # end def attribute(attr, options = {}, &block) key = options.fetch(:key, attr) - _attributes_data[attr] = Attribute.new(attr, key, block) + _attributes_data[key] = Attribute.new(attr, block) end # @api private # keys of attributes # @see Serializer::attribute def _attributes - _attributes_data.values.map(&:key) + _attributes_data.keys end # @api private @@ -68,10 +68,10 @@ def _attributes # @see Serializer::attribute # @see Adapter::FragmentCache#fragment_serializer def _attributes_keys - _attributes_data.values - .each_with_object({}) do |attr, hash| - next if attr.key == attr.name - hash[attr.name] = { key: attr.key } + _attributes_data + .each_with_object({}) do |(key, attr), hash| + next if key == attr.name + hash[attr.name] = { key: key } end end end