Class: Rigor::SigGen::LayoutIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/sig_gen/layout_index.rb

Overview

Pre-scans every ‘.rbs` file under the configured `signature_paths` to build a `qualified_class_name →sig_file_path` map.

ADR-14 path-mapper limitation surfaced repeatedly during the self-dogfood: the existing rigor ‘sig/` consolidates multiple `.rb` sources into one `.rbs` file (e.g. `sig/rigor/type.rbs` declares all 14 `Type::*` classes, `sig/rigor.rbs` declares `CLI::TypeOfCommand` and `CLI::TypeScanCommand`). The naive 1:1 mapper writes new files alongside the existing consolidated ones, producing `RBS::DuplicatedMethodDefinition` errors at lookup time.

The index lets PathMapper route a candidate to the consolidated sig file when the class is already declared there, falling back to the 1:1 mirror only when the class has no existing declaration anywhere under the signature tree.

First-found wins on duplicate declarations across files; RBS itself allows the same class to be declared in multiple files for additive member contributions, but the writer only needs one canonical target per class.

Instance Method Summary collapse

Constructor Details

#initialize(signature_paths:, project_root: Dir.pwd) ⇒ LayoutIndex

Returns a new instance of LayoutIndex.

Parameters:

  • signature_paths (Array<String, Pathname>, nil)

    the ‘.rigor.yml`-configured signature directories. When `nil` or empty, falls back to `<project_root>/sig` if it exists (matching `Environment.for_project`’s auto-detection convention).

  • project_root (String, Pathname) (defaults to: Dir.pwd)


37
38
39
40
# File 'lib/rigor/sig_gen/layout_index.rb', line 37

def initialize(signature_paths:, project_root: Dir.pwd)
  @signature_paths = resolve_paths(signature_paths, project_root)
  @index = nil
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/rigor/sig_gen/layout_index.rb', line 51

def empty?
  index.empty?
end

#file_for(class_name) ⇒ Pathname?

Returns absolute path of the sig file that already declares this class, or ‘nil` when no existing declaration is found.

Parameters:

  • class_name (String)

    fully-qualified Ruby class name (e.g. ‘“Rigor::Type::Top”`).

Returns:

  • (Pathname, nil)

    absolute path of the sig file that already declares this class, or ‘nil` when no existing declaration is found.



47
48
49
# File 'lib/rigor/sig_gen/layout_index.rb', line 47

def file_for(class_name)
  index[class_name]
end