Module: CMDx::Validators::Presence
Overview
Validates that a value is present and not empty
This validator ensures that the given value exists and contains meaningful content. It handles different value types appropriately:
-
Strings: checks for non-whitespace characters
-
Collections: checks for non-empty collections
-
Other objects: checks for non-nil values
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ nil
Validates that a value is present and not empty.
Instance Method Details
#call(value, options = {}) ⇒ nil
Validates that a value is present and not empty
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cmdx/validators/presence.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 if match = [:message] if .is_a?(Hash) raise ValidationError, || Locale.t("cmdx.validators.presence") end |