aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/type/integer.rb
blob: 8e6a509b5b77d366f3fa92ce2998a818b2e35f65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module ActiveRecord
  module ConnectionAdapters
    module Type
      class Integer < Value # :nodoc:
        include Numeric

        def type
          :integer
        end

        def klass
          ::Fixnum
        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
end