aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/mutable.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-12 15:13:28 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-13 14:07:41 -0600
commit4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192 (patch)
tree239a8205dc68ac3bada7a2712f52f2defa159f00 /activerecord/lib/active_record/type/mutable.rb
parent8a3046133aba188d81f31b034d6594899b23c70c (diff)
downloadrails-4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192.tar.gz
rails-4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192.tar.bz2
rails-4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192.zip
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.
Diffstat (limited to 'activerecord/lib/active_record/type/mutable.rb')
-rw-r--r--activerecord/lib/active_record/type/mutable.rb16
1 files changed, 16 insertions, 0 deletions
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