Class: Evilution::AST::InheritanceScanner Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInheritanceScanner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def inheritance
  @inheritance
end

Class Method Details

.call(files) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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