decimal.rb 478 字节
Newer Older
1 2 3 4
module ActiveRecord
  module ConnectionAdapters
    module Type
      class Decimal < Value # :nodoc:
5 6
        include Numeric

7 8
        delegate :extract_scale, to: Type

9 10 11
        def type
          :decimal
        end
12

13 14 15 16
        def klass
          ::BigDecimal
        end

17 18 19
        private

        def cast_value(value)
20 21 22 23 24
          if value.respond_to?(:to_d)
            value.to_d
          else
            value.to_s.to_d
          end
25
        end
26 27 28 29
      end
    end
  end
end