Class: Stannum::Constraints::Identity
- Defined in:
- lib/stannum/constraints/identity.rb
Overview
An Identity constraint checks for the exact object given.
Constant Summary collapse
- NEGATED_TYPE =
The :type of the error generated for a matching object.
'stannum.constraints.is_value'
- TYPE =
The :type of the error generated for a non-matching object.
'stannum.constraints.is_not_value'
Instance Attribute Summary collapse
-
#expected_value ⇒ Object
readonly
The expected object.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(expected_value, **options) ⇒ Identity
constructor
A new instance of Identity.
-
#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) ⇒ Identity
Returns a new instance of Identity.
26 27 28 29 30 |
# File 'lib/stannum/constraints/identity.rb', line 26 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.
33 34 35 |
# File 'lib/stannum/constraints/identity.rb', line 33 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.
41 42 43 |
# File 'lib/stannum/constraints/identity.rb', line 41 def matches?(actual) expected_value.equal?(actual) end |