diff options
Diffstat (limited to 'activerecord/lib/active_record/type/integer.rb')
-rw-r--r-- | activerecord/lib/active_record/type/integer.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/integer.rb b/activerecord/lib/active_record/type/integer.rb new file mode 100644 index 0000000000..08477d1303 --- /dev/null +++ b/activerecord/lib/active_record/type/integer.rb @@ -0,0 +1,23 @@ +module ActiveRecord + module Type + class Integer < Value # :nodoc: + include Numeric + + def type + :integer + end + + alias type_cast_for_database type_cast + + private + + def cast_value(value) + case value + when true then 1 + when false then 0 + else value.to_i rescue nil + end + end + end + end +end |