Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Hash#transform_values to clean up AttributeSet #15982

Merged
merged 1 commit into from
Jun 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions activerecord/lib/active_record/attribute_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def [](name)
end

def values_before_type_cast
attributes.each_with_object({}) { |(k, v), h| h[k] = v.value_before_type_cast }
attributes.transform_values(&:value_before_type_cast)
end

def to_hash
initialized_attributes.each_with_object({}) { |(k, v), h| h[k] = v.value }
initialized_attributes.transform_values(&:value)
end
alias_method :to_h, :to_hash

Expand All @@ -43,11 +43,7 @@ def freeze
end

def initialize_dup(_)
@attributes = attributes.dup
attributes.each do |key, attr|
attributes[key] = attr.dup
end

@attributes = attributes.transform_values(&:dup)
super
end

Expand Down
1 change: 1 addition & 0 deletions activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/hash/deep_merge'
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/hash/transform_values'
require 'active_support/core_ext/string/behavior'
require 'active_support/core_ext/kernel/singleton_class'
require 'active_support/core_ext/module/introspection'
Expand Down