diff options
Diffstat (limited to 'activerecord/lib/active_record/type/string.rb')
-rw-r--r-- | activerecord/lib/active_record/type/string.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/string.rb b/activerecord/lib/active_record/type/string.rb new file mode 100644 index 0000000000..fbc0af2c5a --- /dev/null +++ b/activerecord/lib/active_record/type/string.rb @@ -0,0 +1,36 @@ +module ActiveRecord + module Type + class String < Value # :nodoc: + def type + :string + 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) + case value + when ::Numeric, ActiveSupport::Duration then value.to_s + when ::String then ::String.new(value) + when true then "t" + when false then "f" + else super + end + end + + private + + def cast_value(value) + case value + when true then "t" + when false then "f" + # String.new is slightly faster than dup + else ::String.new(value.to_s) + end + end + end + end +end |