Method: Sequel::Plugins::ValidationClassMethods::ClassMethods#validates_numericality_of
- Defined in:
- lib/sequel/plugins/validation_class_methods.rb
permalink #validates_numericality_of(*atts) ⇒ Object
Validates whether an attribute is a number.
Possible Options:
- :message
-
The message to use (default: ‘is not a number’)
- :only_integer
-
Whether only integers are valid values (default: false)
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/sequel/plugins/validation_class_methods.rb', line 295 def validates_numericality_of(*atts) opts = { :message => 'is not a number', :tag => :numericality, }.merge!((atts)) reflect_validation(:numericality, opts, atts) atts << opts validates_each(*atts) do |o, a, v| begin if opts[:only_integer] Kernel.Integer(v.to_s) else Kernel.Float(v.to_s) end rescue o.errors.add(a, opts[:message]) end end end |