Module: ScoutApm::AutoInstrument::ParserImplementation

Defined in:
lib/scout_apm/auto_instrument/parser.rb

Defined Under Namespace

Classes: Rewriter

Class Method Summary collapse

Class Method Details

.rewrite(path, code = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/scout_apm/auto_instrument/parser.rb', line 8

def self.rewrite(path, code = nil)
  code ||= File.read(path)

  ast = ::Parser::CurrentRuby.parse(code)

  buffer = ::Parser::Source::Buffer.new(path)
  buffer.source = code

  rewriter = Rewriter.new

  # Rewrite the AST, returns a String with the new form.
  rewriter.rewrite(buffer, ast)
end