Class: Teek::MethodCoverageService::MethodVisitor Private
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Teek::MethodCoverageService::MethodVisitor
- Defined in:
- lib/teek/method_coverage_service.rb
Overview
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.
Prism AST visitor to extract method definitions with class context
Instance Method Summary collapse
-
#initialize(methods, file) ⇒ MethodVisitor
constructor
private
A new instance of MethodVisitor.
- #visit_class_node(node) ⇒ Object private
- #visit_def_node(node) ⇒ Object private
- #visit_module_node(node) ⇒ Object private
- #visit_singleton_class_node(node) ⇒ Object private
Constructor Details
#initialize(methods, file) ⇒ MethodVisitor
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 MethodVisitor.
202 203 204 205 206 207 |
# File 'lib/teek/method_coverage_service.rb', line 202 def initialize(methods, file) @methods = methods @file = file @namespace_stack = [] # track current class/module nesting @singleton_depth = 0 # track if we're inside class << self 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.
209 210 211 212 213 214 |
# File 'lib/teek/method_coverage_service.rb', line 209 def visit_class_node(node) name = constant_path_to_string(node.constant_path) @namespace_stack.push(name) super @namespace_stack.pop end |
#visit_def_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.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/teek/method_coverage_service.rb', line 229 def visit_def_node(node) return super if @namespace_stack.empty? # skip top-level methods scope = if node.receiver || @singleton_depth > 0 :class else :instance end @methods << { name: node.name.to_s, scope: scope, start_line: node.location.start_line, end_line: node.location.end_line, class_path: @namespace_stack.join("::"), file: @file } super 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.
216 217 218 219 220 221 |
# File 'lib/teek/method_coverage_service.rb', line 216 def visit_module_node(node) name = constant_path_to_string(node.constant_path) @namespace_stack.push(name) super @namespace_stack.pop end |
#visit_singleton_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.
223 224 225 226 227 |
# File 'lib/teek/method_coverage_service.rb', line 223 def visit_singleton_class_node(node) @singleton_depth += 1 super @singleton_depth -= 1 end |