Class: Woods::RubyAnalyzer::ClassAnalyzer

Inherits:
Object
  • Object
show all
Includes:
Ast::SourceSpan, FqnBuilder
Defined in:
lib/woods/ruby_analyzer/class_analyzer.rb

Overview

Extracts class and module definitions from Ruby source code using the AST layer.

Produces ExtractedUnit objects with type :ruby_class or :ruby_module, including metadata about superclass, includes, extends, constants, and method count.

Examples:

analyzer = RubyAnalyzer::ClassAnalyzer.new
units = analyzer.analyze(source: File.read(path), file_path: path)
units.first.type #=> :ruby_class

Instance Method Summary collapse

Constructor Details

#initialize(parser: nil) ⇒ ClassAnalyzer

Returns a new instance of ClassAnalyzer.

Parameters:

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

    Parser instance (creates default if nil)



24
25
26
# File 'lib/woods/ruby_analyzer/class_analyzer.rb', line 24

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

Instance Method Details

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

Analyze source code and extract class/module units.

Parameters:

  • source (String)

    Ruby source code

  • file_path (String)

    Absolute path to the source file

Returns:



33
34
35
36
37
38
# File 'lib/woods/ruby_analyzer/class_analyzer.rb', line 33

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