Module: Woods::RubyAnalyzer

Defined in:
lib/woods/ruby_analyzer.rb,
lib/woods/ruby_analyzer/fqn_builder.rb,
lib/woods/ruby_analyzer/class_analyzer.rb,
lib/woods/ruby_analyzer/trace_enricher.rb,
lib/woods/ruby_analyzer/method_analyzer.rb,
lib/woods/ruby_analyzer/mermaid_renderer.rb,
lib/woods/ruby_analyzer/dataflow_analyzer.rb

Overview

Analyzes plain Ruby source code and produces ExtractedUnit objects.

Orchestrates ClassAnalyzer, MethodAnalyzer, DataFlowAnalyzer, and optional TraceEnricher to extract structured data from Ruby files.

Examples:

Analyze gem source

units = Woods::RubyAnalyzer.analyze(paths: ["lib/"])
units.select { |u| u.type == :ruby_class }.map(&:identifier)

Defined Under Namespace

Modules: FqnBuilder Classes: ClassAnalyzer, DataFlowAnalyzer, MermaidRenderer, MethodAnalyzer, TraceEnricher

Class Method Summary collapse

Class Method Details

.analyze(paths:, trace_data: nil) ⇒ Array<ExtractedUnit>

Analyze Ruby source files and produce ExtractedUnit objects.

Parameters:

  • paths (Array<String>)

    File paths or directories to analyze

  • trace_data (Array<Hash>, nil) (defaults to: nil)

    Optional runtime trace data for enrichment

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/woods/ruby_analyzer.rb', line 27

def analyze(paths:, trace_data: nil)
  files = discover_files(paths)
  return [] if files.empty?

  parser = Ast::Parser.new
  class_analyzer = ClassAnalyzer.new(parser: parser)
  method_analyzer = MethodAnalyzer.new(parser: parser)
  dataflow_analyzer = DataFlowAnalyzer.new(parser: parser)

  units = []

  files.each do |file_path|
    source = read_file(file_path)
    next unless source

    units.concat(class_analyzer.analyze(source: source, file_path: file_path))
    units.concat(method_analyzer.analyze(source: source, file_path: file_path))
  rescue Woods::ExtractionError
    # Skip files that fail to parse
    next
  end

  dataflow_analyzer.annotate(units)
  TraceEnricher.merge(units: units, trace_data: trace_data) if trace_data

  units
end