diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-20 14:36:18 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-05-20 14:36:18 -0700 |
commit | 32218c10fa6072616ea01380bc33f10a89e157ba (patch) | |
tree | 32be0ca8a154adf271b13dd11d804f475a81b251 /activerecord/lib/active_record/connection_adapters/type | |
parent | 52b558695d5a1b33ff21516cbc71d1ae1dee4632 (diff) | |
download | rails-32218c10fa6072616ea01380bc33f10a89e157ba.tar.gz rails-32218c10fa6072616ea01380bc33f10a89e157ba.tar.bz2 rails-32218c10fa6072616ea01380bc33f10a89e157ba.zip |
Delegate `type_cast_for_write` to injected type object
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/type')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/type/numeric.rb | 9 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/type/value.rb | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/type/numeric.rb b/activerecord/lib/active_record/connection_adapters/type/numeric.rb index a440de4d14..a3379831cb 100644 --- a/activerecord/lib/active_record/connection_adapters/type/numeric.rb +++ b/activerecord/lib/active_record/connection_adapters/type/numeric.rb @@ -5,6 +5,15 @@ module ActiveRecord def number? true end + + def type_cast_for_write(value) + case value + when true then 1 + when false then 0 + when ::String then value.presence + else super + end + end end end end diff --git a/activerecord/lib/active_record/connection_adapters/type/value.rb b/activerecord/lib/active_record/connection_adapters/type/value.rb index 506f402fef..ba8f360eb9 100644 --- a/activerecord/lib/active_record/connection_adapters/type/value.rb +++ b/activerecord/lib/active_record/connection_adapters/type/value.rb @@ -8,6 +8,10 @@ module ActiveRecord cast_value(value) unless value.nil? end + def type_cast_for_write(value) + value + end + def text? false end |