Class: Chiridion::Engine::InlineRbsLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/chiridion/engine/inline_rbs_loader.rb

Overview

Extracts RBS type signatures from inline annotations in Ruby source.

Supports the rbs-inline format where types are specified in comments:

# @rbs param: String -- description
# @rbs return: Integer
def method(param)

This is the preferred way to specify types in source code, as it keeps type information co-located with the code. The RbsLoader handles separate sig/ files as a fallback.

Instance Method Summary collapse

Constructor Details

#initialize(verbose, logger) ⇒ InlineRbsLoader

Returns a new instance of InlineRbsLoader.



19
20
21
22
# File 'lib/chiridion/engine/inline_rbs_loader.rb', line 19

def initialize(verbose, logger)
  @verbose = verbose
  @logger  = logger
end

Instance Method Details

#load(source_files) ⇒ Array(Hash, Hash, Hash)

Extract inline RBS annotations from Ruby source files.

Parameters:

  • source_files (Array<String>)

    Paths to Ruby files

Returns:

  • (Array(Hash, Hash, Hash))
    signatures, rbs_file_namespaces, attr_types
    • signatures: class -> method -> signature

    • rbs_file_namespaces: file -> [namespaces] for files with @rbs content

    • attr_types: class -> attr_name -> { type:, desc: } (from #: annotations or @rbs! blocks)



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/chiridion/engine/inline_rbs_loader.rb', line 31

def load(source_files)
  signatures           = {}
  @rbs_file_namespaces = {}
  @attr_types          = {}

  source_files.each do |file|
    next unless File.exist?(file)

    parse_file(file, signatures)
  end

  @logger.info "Extracted inline RBS from #{source_files.size} files" if @verbose && source_files.any?
  [signatures, @rbs_file_namespaces, @attr_types]
end