From 4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 12 Jun 2014 15:13:28 -0600 Subject: Detect in-place changes on mutable AR attributes We have several mutable types on Active Record now. (Serialized, JSON, HStore). We need to be able to detect if these have been modified in place. --- activerecord/lib/active_record/type/mutable.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 activerecord/lib/active_record/type/mutable.rb (limited to 'activerecord/lib/active_record/type/mutable.rb') diff --git a/activerecord/lib/active_record/type/mutable.rb b/activerecord/lib/active_record/type/mutable.rb new file mode 100644 index 0000000000..64cf4b9b93 --- /dev/null +++ b/activerecord/lib/active_record/type/mutable.rb @@ -0,0 +1,16 @@ +module ActiveRecord + module Type + module Mutable + def type_cast_from_user(value) + type_cast_from_database(type_cast_for_database(value)) + end + + # +raw_old_value+ will be the `_before_type_cast` version of the + # value (likely a string). +new_value+ will be the current, type + # cast value. + def changed_in_place?(raw_old_value, new_value) # :nodoc: + raw_old_value != type_cast_for_database(new_value) + end + end + end +end -- cgit v1.2.3