Class: ArchSpec::Rules::Naming::NameSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/rules/naming_rules.rb

Overview

Selects methods whose name matches a regex. A named capture in the regex (such as (?.+)) is exposed to the requires constraint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regex) ⇒ NameSelector

Returns a new instance of NameSelector.

Raises:



60
61
62
63
64
# File 'lib/archspec/rules/naming_rules.rb', line 60

def initialize(regex)
  raise Error, "method_names matching expects a Regexp, got #{regex.inspect}" unless regex.is_a?(Regexp)

  @regex = regex
end

Instance Attribute Details

#regexObject (readonly)

Returns the value of attribute regex.



58
59
60
# File 'lib/archspec/rules/naming_rules.rb', line 58

def regex
  @regex
end

Instance Method Details

#describeObject



70
71
72
# File 'lib/archspec/rules/naming_rules.rb', line 70

def describe
  "matches #{regex.inspect}"
end

#match(definition) ⇒ Object



66
67
68
# File 'lib/archspec/rules/naming_rules.rb', line 66

def match(definition)
  regex.match(definition.name.to_s)
end