Class: Refactor::Rule

Inherits:
Parser::AST::Processor
  • Object
show all
Includes:
RuboCop::AST::Traversal
Defined in:
lib/refactor.rb

Overview

Wrapper for rule processors to simplify the code needed to run one.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rewriter) ⇒ Rule

Returns a new instance of Rule.



41
42
43
44
# File 'lib/refactor.rb', line 41

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

Instance Attribute Details

#rewriterObject (readonly)

Returns the value of attribute rewriter.



39
40
41
# File 'lib/refactor.rb', line 39

def rewriter
  @rewriter
end

Class Method Details

.process(string) ⇒ Object



46
47
48
# File 'lib/refactor.rb', line 46

def self.process(string)
  Rewriter.new(rules: [self]).process(string)
end

Instance Method Details

#process_regular_node(node) ⇒ Object



50
51
52
53
54
# File 'lib/refactor.rb', line 50

def process_regular_node(node)
  return matches(node) if defined?(matches)

  super()
end