diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-17 18:51:38 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-17 20:09:27 -0600 |
commit | c7802dccba69517083000261477f7e1d410e1cca (patch) | |
tree | 2548317ff70e5e9009da1a1303c5ac7ae425d76c /activerecord/lib/active_record | |
parent | bdc39899ebb2a17e91cfde1803da3d1170531f04 (diff) | |
download | rails-c7802dccba69517083000261477f7e1d410e1cca.tar.gz rails-c7802dccba69517083000261477f7e1d410e1cca.tar.bz2 rails-c7802dccba69517083000261477f7e1d410e1cca.zip |
Detect in-place modifications on Strings
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/type/string.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/type/string.rb b/activerecord/lib/active_record/type/string.rb index 3b1554bd5a..14b03dcb2d 100644 --- a/activerecord/lib/active_record/type/string.rb +++ b/activerecord/lib/active_record/type/string.rb @@ -9,13 +9,28 @@ module ActiveRecord true end + def changed_in_place?(raw_old_value, new_value) + if new_value.is_a?(::String) + raw_old_value != new_value + end + end + + def type_cast_for_database(value) + if value.is_a?(::String) + ::String.new(value) + else + super + end + end + private def cast_value(value) case value when true then "1" when false then "0" - else value.to_s + # String.new is slightly faster than dup + else ::String.new(value.to_s) end end end |