aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-01-31 17:28:04 -0700
committerSean Griffin <sean@thoughtbot.com>2015-01-31 17:29:35 -0700
commitaebba01f437d864baf7165f19737440002016413 (patch)
tree7581aed29a35c9fb5bed4ae8685d4b7586de8bda
parent6b4a5952d3952ffc98173626e8d76e73e6140e3a (diff)
downloadrails-aebba01f437d864baf7165f19737440002016413.tar.gz
rails-aebba01f437d864baf7165f19737440002016413.tar.bz2
rails-aebba01f437d864baf7165f19737440002016413.zip
Remove `AttributeSet#initialized_keys`
This method doesn't need to be lazy, as it is never called from reads. The only time it is called are in write cases, where we're about to loop through the results of it, and build the attribute objects anyway. So we don't gain anything by dodging the instantiation here. This is the only method that coupled `AttributeSet` to `LazyAttributeHash`, so removing it puts us back in a place where we can use a normal hash instead.
-rw-r--r--activerecord/lib/active_record/attribute_set.rb2
-rw-r--r--activerecord/lib/active_record/attribute_set/builder.rb6
2 files changed, 2 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb
index fdce68ce45..0c9793d470 100644
--- a/activerecord/lib/active_record/attribute_set.rb
+++ b/activerecord/lib/active_record/attribute_set.rb
@@ -24,7 +24,7 @@ module ActiveRecord
end
def keys
- attributes.initialized_keys
+ attributes.each_key.select { |name| self[name].initialized? }
end
def fetch_value(name)
diff --git a/activerecord/lib/active_record/attribute_set/builder.rb b/activerecord/lib/active_record/attribute_set/builder.rb
index 3a76f5262d..0f3c285a80 100644
--- a/activerecord/lib/active_record/attribute_set/builder.rb
+++ b/activerecord/lib/active_record/attribute_set/builder.rb
@@ -20,7 +20,7 @@ module ActiveRecord
end
class LazyAttributeHash # :nodoc:
- delegate :select, :transform_values, to: :materialize
+ delegate :select, :transform_values, :each_key, to: :materialize
def initialize(types, values, additional_types)
@types = types
@@ -45,10 +45,6 @@ module ActiveRecord
delegate_hash[key] = value
end
- def initialized_keys
- delegate_hash.keys | values.keys
- end
-
def initialize_dup(_)
@delegate_hash = delegate_hash.transform_values(&:dup)
super