aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_set
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/attribute_set')
-rw-r--r--activerecord/lib/active_record/attribute_set/builder.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_set/builder.rb b/activerecord/lib/active_record/attribute_set/builder.rb
index 3a76f5262d..e85777c335 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 :transform_values, :each_key, to: :materialize
def initialize(types, values, additional_types)
@types = types
@@ -45,15 +45,21 @@ 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
end
+ def select
+ keys = types.keys | values.keys | delegate_hash.keys
+ keys.each_with_object({}) do |key, hash|
+ attribute = self[key]
+ if yield(key, attribute)
+ hash[key] = attribute
+ end
+ end
+ end
+
protected
attr_reader :types, :values, :additional_types, :delegate_hash