Class: RubyDetective::AST::FileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_detective/ast/file_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, project_path) ⇒ FileParser

Returns a new instance of FileParser.



6
7
8
9
# File 'lib/ruby_detective/ast/file_parser.rb', line 6

def initialize(file_path, project_path)
  @path = file_path
  @project_path = project_path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/ruby_detective/ast/file_parser.rb', line 4

def path
  @path
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



4
5
6
# File 'lib/ruby_detective/ast/file_parser.rb', line 4

def project_path
  @project_path
end

#rich_astObject (readonly)

Returns the value of attribute rich_ast.



4
5
6
# File 'lib/ruby_detective/ast/file_parser.rb', line 4

def rich_ast
  @rich_ast
end

Instance Method Details

#parseObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_detective/ast/file_parser.rb', line 11

def parse
  code = File.read(path)

  raw_ast = Parser::CurrentRuby.parse(code)
  return false if raw_ast.nil? # Empty file scenario

  factory = AST::NodeFactory.new(raw_ast, file_path: clean_path)
  @rich_ast = factory.build
  factory.process_all_children

  AST::Interpreter.interpret_node_and_populate_store(
    rich_ast,
    clean_path
  )
end