Class: Evilution::AST::SubjectFinder
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Evilution::AST::SubjectFinder
- Defined in:
- lib/evilution/ast/parser.rb
Instance Attribute Summary collapse
-
#subjects ⇒ Object
readonly
Returns the value of attribute subjects.
Instance Method Summary collapse
-
#initialize(source, file_path) ⇒ SubjectFinder
constructor
A new instance of SubjectFinder.
- #visit_class_node(node) ⇒ Object
- #visit_def_node(node) ⇒ Object
- #visit_module_node(node) ⇒ Object
Constructor Details
#initialize(source, file_path) ⇒ SubjectFinder
Returns a new instance of SubjectFinder.
35 36 37 38 39 40 |
# File 'lib/evilution/ast/parser.rb', line 35 def initialize(source, file_path) @source = source @file_path = file_path @subjects = [] @context = [] end |
Instance Attribute Details
#subjects ⇒ Object (readonly)
Returns the value of attribute subjects.
33 34 35 |
# File 'lib/evilution/ast/parser.rb', line 33 def subjects @subjects end |
Instance Method Details
#visit_class_node(node) ⇒ Object
48 49 50 51 52 |
# File 'lib/evilution/ast/parser.rb', line 48 def visit_class_node(node) @context.push(constant_name(node.constant_path)) super @context.pop end |
#visit_def_node(node) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/evilution/ast/parser.rb', line 54 def visit_def_node(node) scope = @context.join("::") name = if scope.empty? "##{node.name}" else "#{scope}##{node.name}" end loc = node.location method_source = @source[loc.start_offset...loc.end_offset] @subjects << Subject.new( name: name, file_path: @file_path, line_number: loc.start_line, source: method_source, node: node ) super end |
#visit_module_node(node) ⇒ Object
42 43 44 45 46 |
# File 'lib/evilution/ast/parser.rb', line 42 def visit_module_node(node) @context.push(constant_name(node.constant_path)) super @context.pop end |