From 8e633e505880755e7e366ccec2210bbe2b5436e7 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 24 Sep 2015 11:50:11 -0600 Subject: Clean up the implementation of AR::Dirty This moves a bit more of the logic required for dirty checking into the attribute objects. I had hoped to remove the `with_value_from_database` stuff, but unfortunately just calling `dup` on the attribute objects isn't enough, since the values might contain deeply nested data structures. I think this can be cleaned up further. This makes most dirty checking become lazy, and reduces the number of object allocations and amount of CPU time when assigning a value. This opens the door (but doesn't quite finish) to improving the performance of writes to a place comparable to 4.1 --- .../lib/active_model/type/helpers/accepts_multiparameter_time.rb | 8 ++++++++ activemodel/lib/active_model/type/value.rb | 3 +++ 2 files changed, 11 insertions(+) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/type/helpers/accepts_multiparameter_time.rb b/activemodel/lib/active_model/type/helpers/accepts_multiparameter_time.rb index fa1ccd057e..facea12704 100644 --- a/activemodel/lib/active_model/type/helpers/accepts_multiparameter_time.rb +++ b/activemodel/lib/active_model/type/helpers/accepts_multiparameter_time.rb @@ -11,6 +11,14 @@ module ActiveModel end end + define_method(:assert_valid_value) do |value| + if value.is_a?(Hash) + value_from_multiparameter_assignment(value) + else + super(value) + end + end + define_method(:value_from_multiparameter_assignment) do |values_hash| defaults.each do |k, v| values_hash[k] ||= v diff --git a/activemodel/lib/active_model/type/value.rb b/activemodel/lib/active_model/type/value.rb index c7d1197d69..5fea0561a6 100644 --- a/activemodel/lib/active_model/type/value.rb +++ b/activemodel/lib/active_model/type/value.rb @@ -91,6 +91,9 @@ module ActiveModel limit == other.limit end + def assert_valid_value(*) + end + private # Convenience method for types which do not need separate type casting -- cgit v1.2.3