Class: Stannum::Constraints::Properties::Base

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

Overview

Abstract base class for property constraints.

Direct Known Subclasses

Matching

Constant Summary collapse

FILTERED_PARAMETERS =

Default parameter names to filter out of errors.

%i[
  passw
  secret
  token
  _key
  crypt
  salt
  certificate
  otp
  ssn
].freeze

Constants inherited from Base

Base::NEGATED_TYPE, Base::TYPE

Instance Attribute Summary collapse

Attributes inherited from Base

#options

Instance Method Summary collapse

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(*property_names, **options) ⇒ Base

Returns a new instance of Base.

Parameters:

  • property_names (Array<String, Symbol>)

    the name or names of the properties to match.

  • 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.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/stannum/constraints/properties/base.rb', line 32

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

  validate_property_names

  super(
    allow_empty:    !!options[:allow_empty],
    allow_nil:      !!options[:allow_nil],
    property_names: property_names,
    **options
  )
end

Instance Attribute Details

#property_namesArray<String, Symbol> (readonly)

Returns the name or names of the properties to match.

Returns:

  • (Array<String, Symbol>)

    the name or names of the properties to match.



47
48
49
# File 'lib/stannum/constraints/properties/base.rb', line 47

def property_names
  @property_names
end

Instance Method Details

#allow_empty?true, false

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

Returns:

  • (true, false)

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



51
52
53
# File 'lib/stannum/constraints/properties/base.rb', line 51

def allow_empty?
  options[:allow_empty]
end

#allow_nil?true, false

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

Returns:

  • (true, false)

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



57
58
59
# File 'lib/stannum/constraints/properties/base.rb', line 57

def allow_nil?
  options[:allow_nil]
end