Skip to content

Commit

Permalink
Remove key from Attribute class.
Browse files Browse the repository at this point in the history
  • Loading branch information
beauby committed Dec 30, 2015
1 parent 7d24cbf commit a586a45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/active_model/serializer/attribute.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
18 changes: 9 additions & 9 deletions lib/active_model/serializer/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,25 +53,25 @@ 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
# maps attribute value to explict key name
# @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
Expand Down

0 comments on commit a586a45

Please sign in to comment.