Class: TheSchemaIs::Cops::Patterns
- Inherits:
-
Object
- Object
- TheSchemaIs::Cops::Patterns
- Extended by:
- Memoist, RuboCop::AST::NodePattern::Macros
- Includes:
- Singleton
- Defined in:
- lib/the_schema_is/cops/node_util.rb
Overview
This module mitigates usage of RuboCop’s NodePattern in a more flexible manner. NodePattern (targeting RuboCop’s goals) was only available as a metaprogramming macro, requiring to ‘def_node_search :some_method, pattern` before the pattern can be used, while we wanted to just do `ast.ast_search(some_pattern)`; so this method defines a method for each used pattern on the fly and hides this discrepancy. Used by NodeRefinements (mixed into parser’s node) to provide ‘Node#ast_search` and `Node#ast_match`.
Class Method Summary collapse
Class Method Details
.match(pattern, node) ⇒ Object
24 25 26 |
# File 'lib/the_schema_is/cops/node_util.rb', line 24 def match(pattern, node) match_methods[pattern].then { |m| instance.send(m, node) } end |
.search(pattern, node) ⇒ Object
20 21 22 |
# File 'lib/the_schema_is/cops/node_util.rb', line 20 def search(pattern, node) search_methods[pattern].then { |m| instance.send(m, node) } end |