Class: Evilution::AST::InheritanceScanner

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/evilution/ast/inheritance_scanner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInheritanceScanner

Returns a new instance of InheritanceScanner.



10
11
12
13
14
# File 'lib/evilution/ast/inheritance_scanner.rb', line 10

def initialize
  @inheritance = {}
  @context = []
  super
end

Instance Attribute Details

#inheritanceObject (readonly)

Returns the value of attribute inheritance.



8
9
10
# File 'lib/evilution/ast/inheritance_scanner.rb', line 8

def inheritance
  @inheritance
end

Class Method Details

.call(files) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/evilution/ast/inheritance_scanner.rb', line 16

def self.call(files)
  scanner = new
  files.each do |file|
    source = File.read(file)
    result = Prism.parse(source)
    next if result.failure?

    scanner.visit(result.value)
  rescue SystemCallError
    next
  end
  scanner.inheritance
end

Instance Method Details

#visit_class_node(node) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/evilution/ast/inheritance_scanner.rb', line 30

def visit_class_node(node)
  class_name = qualified_name(node.constant_path)

  @inheritance[class_name] = (qualified_superclass(node.superclass) if node.superclass)

  @context.push(constant_name(node.constant_path))
  super
  @context.pop
end

#visit_module_node(node) ⇒ Object



40
41
42
43
44
# File 'lib/evilution/ast/inheritance_scanner.rb', line 40

def visit_module_node(node)
  @context.push(constant_name(node.constant_path))
  super
  @context.pop
end