Class: Stannum::Constraints::Equality
- Defined in:
- lib/stannum/constraints/equality.rb
Overview
An Equality constraint uses #== to compare the actual and expected objects.
Constant Summary collapse
- NEGATED_TYPE =
The :type of the error generated for a matching object.
'stannum.constraints.is_equal_to'
- TYPE =
The :type of the error generated for a non-matching object.
'stannum.constraints.is_not_equal_to'
Instance Attribute Summary collapse
-
#expected_value ⇒ Object
readonly
The expected object.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(expected_value, **options) ⇒ Equality
constructor
A new instance of Equality.
-
#matches?(actual) ⇒ true, false
(also: #match?)
Checks that the object is the expected value.
Methods inherited from Base
#==, #clone, #does_not_match?, #dup, #errors_for, #match, #message, #negated_errors_for, #negated_match, #negated_message, #negated_type, #type, #with_options
Constructor Details
#initialize(expected_value, **options) ⇒ Equality
Returns a new instance of Equality.
27 28 29 30 31 |
# File 'lib/stannum/constraints/equality.rb', line 27 def initialize(expected_value, **) @expected_value = expected_value super(expected_value: expected_value, **) end |
Instance Attribute Details
#expected_value ⇒ Object (readonly)
Returns the expected object.
34 35 36 |
# File 'lib/stannum/constraints/equality.rb', line 34 def expected_value @expected_value end |
Instance Method Details
#matches?(actual) ⇒ true, false Also known as: match?
Checks that the object is the expected value.
42 43 44 |
# File 'lib/stannum/constraints/equality.rb', line 42 def matches?(actual) expected_value == actual end |