Class: CallMap::CallExtractor
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- CallMap::CallExtractor
- Defined in:
- lib/call_map/call_extractor.rb
Overview
Extracts method calls from a method body's AST.
Like DefinitionCollector, this is a Prism boundary class — Prism node types are referenced only here.
Constant Summary collapse
- DYNAMIC_METHODS =
%w[send public_send __send__].freeze
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
Class Method Summary collapse
-
.extract(def_node) ⇒ Array<MethodCall>
Extract calls from a DefNode's body.
Instance Method Summary collapse
-
#initialize ⇒ CallExtractor
constructor
A new instance of CallExtractor.
- #visit_call_node(node) ⇒ Object
-
#visit_def_node(_node) ⇒ Object
Do not recurse into nested def bodies — they are not executed as part of the enclosing method's call path.
Constructor Details
#initialize ⇒ CallExtractor
Returns a new instance of CallExtractor.
24 25 26 27 |
# File 'lib/call_map/call_extractor.rb', line 24 def initialize super @calls = [] end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
29 30 31 |
# File 'lib/call_map/call_extractor.rb', line 29 def calls @calls end |
Class Method Details
.extract(def_node) ⇒ Array<MethodCall>
Extract calls from a DefNode's body.
18 19 20 21 22 |
# File 'lib/call_map/call_extractor.rb', line 18 def self.extract(def_node) extractor = new def_node.body&.accept(extractor) extractor.calls end |
Instance Method Details
#visit_call_node(node) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/call_map/call_extractor.rb', line 31 def visit_call_node(node) @calls << build_call(node) # Walk arguments and block, but not the receiver itself (it is already # captured in the receiver label). However, walk the receiver chain's # arguments/blocks so that calls like `SomeClass.new(build_order).execute` # still extract `build_order`. node.arguments&.accept(self) node.block&.accept(self) walk_receiver_args(node.receiver) end |
#visit_def_node(_node) ⇒ Object
Do not recurse into nested def bodies — they are not executed as part of the enclosing method's call path.
44 |
# File 'lib/call_map/call_extractor.rb', line 44 def visit_def_node(_node); end |