Class: Evilution::AST::InheritanceScanner
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Evilution::AST::InheritanceScanner
- Defined in:
- lib/evilution/ast/inheritance_scanner.rb
Instance Attribute Summary collapse
-
#inheritance ⇒ Object
readonly
Returns the value of attribute inheritance.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ InheritanceScanner
constructor
A new instance of InheritanceScanner.
- #visit_class_node(node) ⇒ Object
- #visit_module_node(node) ⇒ Object
Constructor Details
#initialize ⇒ InheritanceScanner
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
#inheritance ⇒ Object (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 |