Sha256: d5dfc1826f240f6334d4dc41c58d878c5779eeff8c91a4ef54d11aa1583c5317

Contents?: true

Size: 784 Bytes

Versions: 5

Compression:

Stored size: 784 Bytes

Contents

# encoding: utf-8

require 'dm-core'
require 'dm-postgres-types/property/pg_array'

module DataMapper
  class Property
    class PgNumericArray < PgArray
      accept_options :precision, :scale
      attr_reader :precision, :scale

      def initialize(model, name, options = {})
        super
        @precision = @options[:precision] || 10
        @scale     = @options[:scale]     || 0

        if precision <= 0
          raise ArgumentError, "precision must be greater than 0"
        end

        if scale <= 0
          raise ArgumentError, "scale must be greater than or equal to 0"
        end        
      end

      def load(value)
        values = super
        values.map! { |val| (scale > 0) ? val.to_f : val.to_i } if values
        values
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dm-postgres-types-0.0.5 lib/dm-postgres-types/property/pg_numeric_array.rb
dm-postgres-types-0.0.4 lib/dm-postgres-types/property/pg_numeric_array.rb
dm-postgres-types-0.0.3 lib/dm-postgres-types/property/pg_numeric_array.rb
dm-postgres-types-0.0.2 lib/dm-postgres-types/property/pg_numeric_array.rb
dm-postgres-types-0.0.1 lib/dm-postgres-types/property/pg_numeric_array.rb