Module: CMDx::Validators::Inclusion
Overview
Validates that a value is included in a specified set or range
This validator ensures that the given value is present within a collection of allowed values or falls within a specified range. It supports both discrete value lists and range-based validations.
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ nil
Validates that a value is included in the specified options.
Instance Method Details
#call(value, options = {}) ⇒ nil
Validates that a value is included in the specified options
39 40 41 42 43 44 45 46 47 |
# File 'lib/cmdx/validators/inclusion.rb', line 39 def call(value, = {}) values = [:in] || [:within] if values.is_a?(Range) raise_within_validation_error!(values.begin, values.end, ) unless values.cover?(value) elsif Array(values).none? { |v| v === value } raise_of_validation_error!(values, ) end end |