Class: KeyVortex::Constraint::Regexp

Inherits:
Base
  • Object
show all
Defined in:
lib/key_vortex/constraint/regexp.rb

Overview

Enforces that strings match the specified pattern. Because regular expressions are too complicated to establish clean bounds, it will not be considered when narrowing based on adapter constraints.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#applies_to?, #to_s

Constructor Details

#initialize(pattern) ⇒ Regexp

Returns a new instance of Regexp.

Parameters:

  • pattern (Regexp)

    The regexp the value must match



16
17
18
19
# File 'lib/key_vortex/constraint/regexp.rb', line 16

def initialize(pattern)
  super()
  @pattern = pattern
end

Instance Attribute Details

#patternRegexp (readonly)

Returns The regexp the value must match.

Returns:

  • (Regexp)

    The regexp the value must match



13
14
15
# File 'lib/key_vortex/constraint/regexp.rb', line 13

def pattern
  @pattern
end

Instance Method Details

#accepts?(value) ⇒ Boolean

Returns True if pattern =~ value.

Parameters:

  • value (String)

Returns:

  • (Boolean)

    True if pattern =~ value



34
35
36
# File 'lib/key_vortex/constraint/regexp.rb', line 34

def accepts?(value)
  pattern =~ value
end

#attributeSymbol

Returns :regexp.

Returns:

  • (Symbol)

    :regexp



22
23
24
# File 'lib/key_vortex/constraint/regexp.rb', line 22

def attribute
  :regexp
end

#within?(_) ⇒ true

Returns Regular expressions are too flexible, they cannot be compared.

Parameters:

  • (any)

Returns:

  • (true)

    Regular expressions are too flexible, they cannot be compared



28
29
30
# File 'lib/key_vortex/constraint/regexp.rb', line 28

def within?(_)
  true
end