Module: CMDx::Validators::Numeric
Overview
Validates numeric values against various constraints and ranges
This validator ensures that numeric values meet specified criteria such as minimum/maximum bounds, exact matches, or range inclusions. It supports both inclusive and exclusive range validations with customizable error messages.
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ nil
Validates a numeric value against the specified options.
Instance Method Details
#call(value, options = {}) ⇒ nil
Validates a numeric value against the specified options
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cmdx/validators/numeric.rb', line 53 def call(value, = {}) case in within: raise_within_validation_error!(within.begin, within.end, ) unless within&.cover?(value) in not_within: raise_not_within_validation_error!(not_within.begin, not_within.end, ) if not_within&.cover?(value) in in: xin raise_within_validation_error!(xin.begin, xin.end, ) unless xin&.cover?(value) in not_in: raise_not_within_validation_error!(not_in.begin, not_in.end, ) if not_in&.cover?(value) in min:, max: raise_within_validation_error!(min, max, ) unless value&.between?(min, max) in min: raise_min_validation_error!(min, ) unless !value.nil? && (min <= value) in max: raise_max_validation_error!(max, ) unless !value.nil? && (value <= max) in is: raise_is_validation_error!(is, ) unless !value.nil? && (value == is) in is_not: raise_is_not_validation_error!(is_not, ) if !value.nil? && (value == is_not) else raise ArgumentError, "unknown numeric validator options given" end end |