Sha256: ab48ac967d0d41b80f44034827fad2c640ccedefdd5eb5df99a3cfbf126d2ac6

Contents?: true

Size: 1016 Bytes

Versions: 1

Compression:

Stored size: 1016 Bytes

Contents

module DataMapper
  class Property
    class Decimal < Numeric
      load_as         BigDecimal
      dump_as         BigDecimal
      coercion_method :to_decimal

      DEFAULT_PRECISION = 10
      DEFAULT_SCALE     = 0

      precision(DEFAULT_PRECISION)
      scale(DEFAULT_SCALE)

    protected

      def initialize(model, name, options = {})
        super

        [ :scale, :precision ].each do |key|
          unless @options.key?(key)
            warn "options[#{key.inspect}] should be set for #{self.class}, defaulting to #{send(key).inspect} (#{caller.first})"
          end
        end

        unless @scale >= 0
          raise ArgumentError, "scale must be equal to or greater than 0, but was #{@scale.inspect}"
        end

        unless @precision >= @scale
          raise ArgumentError, "precision must be equal to or greater than scale, but was #{@precision.inspect} and scale was #{@scale.inspect}"
        end
      end

    end # class Decimal
  end # class Property
end # module DataMapper

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ghost_dm-core-1.3.0.beta lib/dm-core/property/decimal.rb