Class: Rigor::SigGen::PathMapper
- Inherits:
-
Object
- Object
- Rigor::SigGen::PathMapper
- Defined in:
- lib/rigor/sig_gen/path_mapper.rb
Overview
Maps a source .rb file to its target .rbs sig file under the project's signature tree.
ADR-14 § "Output layout":
--writeMUST NOT touch files outsideconfiguration.signature_paths(defaultsig/).- The first slice supports one source file → one RBS file; multi-class files emit one RBS containing both classes (handled by the Writer, not here).
The mapping convention mirrors the Ruby community default: strip the source root prefix (the first entry
of configuration.paths, typically "lib"), swap the extension, and place the result under the first
entry of configuration.signature_paths (typically "sig").
ADR-14 follow-up: when a class is already declared in an existing consolidated sig file (e.g.
sig/rigor/type.rbs holds all Rigor::Type::* classes), the optional LayoutIndex re-routes the target
to that file so the writer updates the consolidated declaration instead of creating a duplicate at the 1:1
mirror path.
When the source path is not under any configured source root (e.g. files supplied directly on the CLI
from outside lib/), the full relative path is preserved under the sig root.
Instance Method Summary collapse
- #existing_target_for(class_name) ⇒ Object
-
#initialize(configuration:, project_root: Dir.pwd, layout_index: nil) ⇒ PathMapper
constructor
A new instance of PathMapper.
-
#sig_root_dir ⇒ Object
The directory
--writeis allowed to create / modify. -
#target_for(source_path, class_name: nil) ⇒ Pathname
Absolute path of the target
.rbsfile for the candidate.
Constructor Details
#initialize(configuration:, project_root: Dir.pwd, layout_index: nil) ⇒ PathMapper
Returns a new instance of PathMapper.
29 30 31 32 33 |
# File 'lib/rigor/sig_gen/path_mapper.rb', line 29 def initialize(configuration:, project_root: Dir.pwd, layout_index: nil) @configuration = configuration @project_root = Pathname(project_root) @layout_index = layout_index end |
Instance Method Details
#existing_target_for(class_name) ⇒ Object
51 52 53 54 55 |
# File 'lib/rigor/sig_gen/path_mapper.rb', line 51 def existing_target_for(class_name) return nil if class_name.nil? || @layout_index.nil? @layout_index.file_for(class_name) end |
#sig_root_dir ⇒ Object
The directory --write is allowed to create / modify. Used by callers to assert the target stays inside
the configured signature tree before touching the disk.
59 60 61 |
# File 'lib/rigor/sig_gen/path_mapper.rb', line 59 def sig_root_dir @sig_root_dir ||= @project_root / sig_root_name end |
#target_for(source_path, class_name: nil) ⇒ Pathname
Returns absolute path of the target .rbs
file for the candidate.
42 43 44 45 46 47 48 49 |
# File 'lib/rigor/sig_gen/path_mapper.rb', line 42 def target_for(source_path, class_name: nil) existing = existing_target_for(class_name) return existing if existing rel_to_root = source_relative_to_root(source_path) stripped = strip_source_root(rel_to_root) sig_root_dir / "#{stripped.sub_ext('')}.rbs" end |