Class: Stannum::Constraints::Absence
- Defined in:
- lib/stannum/constraints/absence.rb
Overview
An absence constraint asserts that the object is nil or empty.
Constant Summary collapse
- NEGATED_TYPE =
The :type of the error generated for a matching object.
Stannum::Constraints::Presence::TYPE
- TYPE =
The :type of the error generated for a non-matching object.
Stannum::Constraints::Presence::NEGATED_TYPE
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#matches?(actual) ⇒ true, false
(also: #match?)
Checks that the object is nil or empty.
Methods inherited from Base
#==, #clone, #does_not_match?, #dup, #errors_for, #initialize, #match, #message, #negated_errors_for, #negated_match, #negated_message, #negated_type, #type, #with_options
Constructor Details
This class inherits a constructor from Stannum::Constraints::Base
Instance Method Details
#matches?(actual) ⇒ true, false Also known as: match?
Checks that the object is nil or empty.
33 34 35 36 37 38 39 |
# File 'lib/stannum/constraints/absence.rb', line 33 def matches?(actual) return true if actual.nil? return true if actual.respond_to?(:empty?) && actual.empty? false end |