Module: DataMapper::Validations::ValidatesNumericality
- Extended by:
- Deprecate
- Included in:
- ClassMethods
- Defined in:
- lib/dm-validations/validators/numeric_validator.rb
Overview
class NumericalityValidator
Instance Method Summary collapse
-
#validates_numericality_of(*fields) ⇒ Object
Validate whether a field is numeric.
Instance Method Details
#validates_numericality_of(*fields) ⇒ Object
Validate whether a field is numeric
Options are:
:allow_nil => true | false
true if number can be nil, false if not
:allow_blank => true | false
true if number can be blank, false if not
:message => “Error message for %s”
Custom error message, also can be a callable object that takes
an object (for pure Ruby objects) or object and property (for DM resources)
:precision => 2
Required precision of a value
:scale => 2
Required scale of a value
:gte => 5.75
'Greater than or greater' requirement
:lte => 5.75
'Less than or greater' requirement
:lt => 5.75
'Less than' requirement
:gt => 5.75
'Greater than' requirement
:eq => 5.75
'Equal' requirement
:ne => 5.75
'Not equal' requirement
:integer_only => true
Use to restrict allowed values to integers
173 174 175 176 |
# File 'lib/dm-validations/validators/numeric_validator.rb', line 173 def validates_numericality_of(*fields) opts = opts_from_validator_args(fields) add_validator_to_context(opts, fields, DataMapper::Validations::NumericalityValidator) end |