public
Rubygem
Description: DataMapper - Core
Homepage: http://datamapper.org
Clone URL: git://github.com/sam/dm-core.git
Search Repo:
remove scale from required parameters for a float. Default the scale 
parameter
of float to nil.
mayo (author)
Mon Jul 21 12:05:20 -0700 2008
commit  30e4e5810eda0e0f27da684912ff7e33dfc62b28
tree    4c5f5e7ea5a5ee3513b3b985912cfeafa81ab9b7
parent  c01abf0e2e6501c705b9a075601633b16cd193f9
...
595
596
597
598
599
 
 
600
601
602
...
595
596
597
 
 
598
599
600
601
602
0
@@ -595,8 +595,8 @@ module DataMapper
0
               tm.map(String).to('VARCHAR').with(:size => Property::DEFAULT_LENGTH)
0
               tm.map(Class).to('VARCHAR').with(:size => Property::DEFAULT_LENGTH)
0
               tm.map(DM::Discriminator).to('VARCHAR').with(:size => Property::DEFAULT_LENGTH)
0
- tm.map(BigDecimal).to('DECIMAL').with(:precision => Property::DEFAULT_PRECISION, :scale => Property::DEFAULT_SCALE)
0
- tm.map(Float).to('FLOAT').with(:precision => Property::DEFAULT_PRECISION, :scale => Property::DEFAULT_SCALE)
0
+ tm.map(BigDecimal).to('DECIMAL').with(:precision => Property::DEFAULT_PRECISION, :scale => Property::DEFAULT_SCALE_BIGDECIMAL)
0
+ tm.map(Float).to('FLOAT').with(:precision => Property::DEFAULT_PRECISION)
0
               tm.map(DateTime).to('DATETIME')
0
               tm.map(Date).to('DATE')
0
               tm.map(Time).to('TIMESTAMP')
...
274
275
276
277
 
 
278
279
280
...
541
542
543
544
 
 
 
 
545
546
547
548
549
550
551
552
 
 
 
 
553
554
555
 
 
 
556
557
558
...
274
275
276
 
277
278
279
280
281
...
542
543
544
 
545
546
547
548
549
550
551
552
553
 
 
 
554
555
556
557
558
 
 
559
560
561
562
563
564
0
@@ -274,7 +274,8 @@ module DataMapper
0
 
0
     DEFAULT_LENGTH = 50
0
     DEFAULT_PRECISION = 10
0
- DEFAULT_SCALE = 0
0
+ DEFAULT_SCALE_BIGDECIMAL = 0
0
+ DEFAULT_SCALE_FLOAT = nil
0
 
0
     attr_reader :primitive, :model, :name, :instance_variable_name,
0
       :type, :reader_visibility, :writer_visibility, :getter, :options,
0
@@ -541,18 +542,23 @@ module DataMapper
0
         @length = @options.fetch(:length, @options.fetch(:size, DEFAULT_LENGTH))
0
       elsif BigDecimal == @primitive || Float == @primitive
0
         @precision = @options.fetch(:precision, DEFAULT_PRECISION)
0
- @scale = @options.fetch(:scale, DEFAULT_SCALE)
0
+
0
+ default_scale = (Float == @primitive) ? DEFAULT_SCALE_FLOAT : DEFAULT_SCALE_BIGDECIMAL
0
+ @scale = @options.fetch(:scale, default_scale)
0
+ # @scale = @options.fetch(:scale, DEFAULT_SCALE_BIGDECIMAL)
0
 
0
         unless @precision > 0
0
           raise ArgumentError, "precision must be greater than 0, but was #{@precision.inspect}"
0
         end
0
 
0
- unless @scale >= 0
0
- raise ArgumentError, "scale must be equal to or greater than 0, but was #{@scale.inspect}"
0
- end
0
+ if (BigDecimal == @primitive) || (Float == @primitive && !@scale.nil?)
0
+ unless @scale >= 0
0
+ raise ArgumentError, "scale must be equal to or greater than 0, but was #{@scale.inspect}"
0
+ end
0
 
0
- unless @precision >= @scale
0
- raise ArgumentError, "precision must be equal to or greater than scale, but was #{@precision.inspect} and scale was #{@scale.inspect}"
0
+ unless @precision >= @scale
0
+ raise ArgumentError, "precision must be equal to or greater than scale, but was #{@precision.inspect} and scale was #{@scale.inspect}"
0
+ end
0
         end
0
       end
0
 

Comments

    No one has commented yet.