Class: Stannum::Constraints::Presence
- Defined in:
- lib/stannum/constraints/presence.rb
Overview
A presence constraint asserts that the object is not nil and not empty.
Constant Summary collapse
- NEGATED_TYPE =
The :type of the error generated for a matching object.
'stannum.constraints.present'
- TYPE =
The :type of the error generated for a non-matching object.
'stannum.constraints.absent'
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#matches?(actual) ⇒ true, false
(also: #match?)
Checks that the object is not nil and not 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 not nil and not empty.
33 34 35 36 37 38 39 |
# File 'lib/stannum/constraints/presence.rb', line 33 def matches?(actual) return false if actual.nil? return false if actual.respond_to?(:empty?) && actual.empty? true end |