Class: Woods::RubyAnalyzer::MethodAnalyzer

Inherits:
Object
  • Object
show all
Includes:
FqnBuilder
Defined in:
lib/woods/ruby_analyzer/method_analyzer.rb

Overview

Extracts method-level units from Ruby source code.

For each class/module, extracts methods as ExtractedUnit objects with type :ruby_method. Includes visibility, parameters, call graph, and dependencies.

Examples:

analyzer = RubyAnalyzer::MethodAnalyzer.new
units = analyzer.analyze(source: File.read(path), file_path: path)
units.first.identifier #=> "MyClass#my_method"

Defined Under Namespace

Classes: VisibilityTracker

Instance Method Summary collapse

Constructor Details

#initialize(parser: nil) ⇒ MethodAnalyzer

Returns a new instance of MethodAnalyzer.

Parameters:

  • parser (Ast::Parser, nil) (defaults to: nil)

    Parser instance (creates default if nil)



25
26
27
28
# File 'lib/woods/ruby_analyzer/method_analyzer.rb', line 25

def initialize(parser: nil)
  @parser = parser || Ast::Parser.new
  @call_site_extractor = Ast::CallSiteExtractor.new
end

Instance Method Details

#analyze(source:, file_path:) ⇒ Array<ExtractedUnit>

Analyze source code and extract method units.

Parameters:

  • source (String)

    Ruby source code

  • file_path (String)

    Absolute path to the source file

Returns:



35
36
37
38
39
40
# File 'lib/woods/ruby_analyzer/method_analyzer.rb', line 35

def analyze(source:, file_path:)
  root = @parser.parse(source)
  units = []
  extract_methods_from_tree(root, source, file_path, [], units)
  units
end