Module: CMDx::Validators::Presence
Overview
Validates that a value is present: non-‘nil`, non-empty, and (for strings) not whitespace-only.
Instance Method Summary collapse
Instance Method Details
#call(value, options = EMPTY_HASH) ⇒ Validators::Failure?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cmdx/validators/presence.rb', line 15 def call(value, = EMPTY_HASH) present = if value.is_a?(String) /\S/.match?(value) elsif value.respond_to?(:empty?) !value.empty? else !value.nil? end return if present Failure.new([:message] || I18nProxy.t("cmdx.validators.presence")) end |