Class: Stannum::Constraints::Properties::Matching

Inherits:
Base
  • Object
show all
Defined in:
lib/stannum/constraints/properties/matching.rb

Overview

Abstract base class for property matching constraints.

Direct Known Subclasses

DoNotMatchProperty, MatchProperty

Constant Summary

Constants inherited from Base

Base::FILTERED_PARAMETERS

Constants inherited from Base

Base::NEGATED_TYPE, Base::TYPE

Instance Attribute Summary collapse

Attributes inherited from Base

#property_names

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#allow_empty?, #allow_nil?

Methods inherited from Base

#==, #clone, #does_not_match?, #dup, #errors_for, #match, #matches?, #message, #negated_errors_for, #negated_match, #negated_message, #negated_type, #type, #with_options

Constructor Details

#initialize(reference_name, *property_names, **options) ⇒ Matching

Returns a new instance of Matching.

Parameters:

  • reference_name (String, Symbol)

    the name of the reference property to compare to.

  • property_names (Array<String, Symbol>)

    the name or names of the properties to compare.

  • options (Hash<Symbol, Object>)

    configuration options for the constraint. Defaults to an empty Hash.

Options Hash (**options):

  • allow_empty (true, false)

    if true, will match against an object with empty property values, such as an empty string.

  • allow_nil (true, false)

    if true, will match against an object with nil property values.



20
21
22
23
24
25
26
# File 'lib/stannum/constraints/properties/matching.rb', line 20

def initialize(reference_name, *property_names, **options)
  @reference_name = reference_name

  validate_reference_name

  super(*property_names, reference_name: reference_name, **options)
end

Instance Attribute Details

#reference_nameString, Symbol (readonly)

Returns the name of the reference property to compare to.

Returns:

  • (String, Symbol)

    the name of the reference property to compare to.



29
30
31
# File 'lib/stannum/constraints/properties/matching.rb', line 29

def reference_name
  @reference_name
end