Module: CMDx::Validators::Exclusion
Overview
Inverse of Inclusion: the value must not be within the given enumerable or ‘Range`.
Instance Method Summary collapse
Instance Method Details
#call(value, options = EMPTY_HASH) ⇒ Validators::Failure?
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cmdx/validators/exclusion.rb', line 20 def call(value, = EMPTY_HASH) values = [:in] || [:within] raise ArgumentError, "exclusion validator requires :in or :within option" if values.nil? if values.is_a?(Range) within_failure(values.begin, values.end, ) if values.cover?(value) elsif Array(values).any? { |v| v === value } of_failure(values, ) end end |