Module: CMDx::Validators::Absence
Overview
Validates that a value is absent or empty
This validator ensures that the given value is nil, empty, or consists only of whitespace. It handles different value types appropriately:
-
Strings: checks for absence of non-whitespace characters
-
Collections: checks for empty collections
-
Other objects: checks for nil values
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ nil
Validates that a value is absent or empty.
Instance Method Details
#call(value, options = {}) ⇒ nil
Validates that a value is absent or empty
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cmdx/validators/absence.rb', line 43 def call(value, = {}) match = if value.is_a?(String) /\S/.match?(value) elsif value.respond_to?(:empty?) !value.empty? else !value.nil? end return unless match = [:message] if .is_a?(Hash) raise ValidationError, || Locale.t("cmdx.validators.absence") end |