decimal.rb 431 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
module ActiveRecord
  module Type
    class Decimal < Value # :nodoc:
      include Numeric

      def type
        :decimal
      end

      def klass
        ::BigDecimal
      end

14 15 16 17
      def type_cast_for_schema(value)
        value.to_s
      end

18 19 20 21 22 23 24 25 26 27 28 29
      private

      def cast_value(value)
        if value.respond_to?(:to_d)
          value.to_d
        else
          value.to_s.to_d
        end
      end
    end
  end
end