Class: DataMapper::Property::Numeric
- Inherits:
-
Object
- Object
- DataMapper::Property
- Object
- DataMapper::Property::Numeric
- Includes:
- PassThroughLoadDump, Typecast::Numeric
- Defined in:
- lib/dm-core/property/numeric.rb
Constant Summary collapse
- DEFAULT_PRECISION =
10
- DEFAULT_NUMERIC_MIN =
0
- DEFAULT_NUMERIC_MAX =
2**31-1
Constants inherited from DataMapper::Property
INVALID_NAMES, OPTIONS, PRIMITIVES, VISIBILITY_OPTIONS
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Attributes inherited from DataMapper::Property
#allow_blank, #allow_nil, #default, #index, #instance_variable_name, #model, #name, #options, #primitive, #reader_visibility, #repository_name, #required, #unique_index, #writer_visibility
Instance Method Summary collapse
-
#initialize(model, name, options = {}) ⇒ Numeric
constructor
protected
A new instance of Numeric.
Methods included from Typecast::Numeric
Methods included from PassThroughLoadDump
Methods inherited from Object
Methods inherited from DataMapper::Property
accept_options, accepted_options, #allow_blank?, #allow_nil?, #assert_valid_options, #bind, demodulized_names, descendants, determine_class, #determine_visibility, #field, find_class, #get, #get!, inherited, #inspect, #key?, #lazy?, #lazy_load, #lazy_load_properties, #loaded?, nullable, options, #primitive?, #properties, #required?, #serial?, #set, #set!, #typecast, #unique?, #valid?
Methods included from Chainable
Methods included from Equalizer
Methods included from Deprecate
Methods included from Subject
Methods included from Assertions
Constructor Details
#initialize(model, name, options = {}) ⇒ Numeric (protected)
Returns a new instance of Numeric.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dm-core/property/numeric.rb', line 18 def initialize(model, name, = {}) super if @primitive == BigDecimal || @primitive == ::Float @precision = @options.fetch(:precision, DEFAULT_PRECISION) @scale = @options.fetch(:scale, self.class::DEFAULT_SCALE) unless @precision > 0 raise ArgumentError, "precision must be greater than 0, but was #{@precision.inspect}" end end if @options.key?(:min) || @options.key?(:max) @min = @options.fetch(:min, DEFAULT_NUMERIC_MIN) @max = @options.fetch(:max, DEFAULT_NUMERIC_MAX) if @max < DEFAULT_NUMERIC_MIN && !@options.key?(:min) raise ArgumentError, "min should be specified when the max is less than #{DEFAULT_NUMERIC_MIN}" elsif @max < @min raise ArgumentError, "max must be less than the min, but was #{@max} while the min was #{@min}" end end end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
10 11 12 |
# File 'lib/dm-core/property/numeric.rb', line 10 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
10 11 12 |
# File 'lib/dm-core/property/numeric.rb', line 10 def min @min end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
10 11 12 |
# File 'lib/dm-core/property/numeric.rb', line 10 def precision @precision end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
10 11 12 |
# File 'lib/dm-core/property/numeric.rb', line 10 def scale @scale end |