Module: Rigor::Environment::RbsCollectionDiscovery
- Defined in:
- lib/rigor/environment/rbs_collection_discovery.rb
Overview
Open item O4 Layer 3 slice 2 — ‘rbs collection install` awareness.
When the target project has been set up with ‘rbs collection install` (the standard RBS-ecosystem flow for pulling community RBS from github.com/ruby/gem_rbs_collection), a `rbs_collection.lock.yaml` records the resolved (gem, version, source) triples and `.gem_rbs_collection/<name>/ <version>/` carries the actual `.rbs` files. This module parses the lockfile and returns the per-gem RBS directory paths so they can be appended to `RbsLoader`’s ‘signature_paths:`.
The discovery is intentionally a pure file-system + YAML walk — no Bundler API call, no network access. Failure modes (missing lockfile, malformed YAML, missing collection directory) silently degrade to an empty list.
Constant Summary collapse
- SKIPPED_SOURCE_TYPES =
‘stdlib`-typed entries in the lockfile are loaded into the RBS environment by the standard library mechanism (rigor’s ‘Environment::DEFAULT_LIBRARIES` already covers this surface). Including them as `signature_paths:` entries would risk `RBS::DuplicatedDeclarationError` (the same hazard O7’s failure-memo handles). The other documented source types — ‘git` (the gem_rbs_collection repo), `rubygems` (sigs lifted from a gem’s bundled ‘sig/`), and `local` (a user-managed RBS dir) — all produce a directory under the collection root and are admitted.
Set["stdlib"].freeze
Class Method Summary collapse
-
.discover(lockfile_path:, project_root: Dir.pwd, auto_detect: true) ⇒ Array<Pathname>
Every ‘<collection_path>/<gem-name>/<gem-version>/` directory listed in the lockfile whose entry has a non-skipped source type and whose directory exists on disk.
-
.resolve_lockfile_path(lockfile_path:, project_root: Dir.pwd, auto_detect: true) ⇒ Object
Returns the resolved lockfile path (‘Pathname`) or `nil` when neither explicit nor auto-detect produces one.
Class Method Details
.discover(lockfile_path:, project_root: Dir.pwd, auto_detect: true) ⇒ Array<Pathname>
Returns every ‘<collection_path>/<gem-name>/<gem-version>/` directory listed in the lockfile whose entry has a non-skipped source type and whose directory exists on disk. Returns `[]` when no lockfile is resolvable, when the YAML is unreadable, or when the collection path doesn’t exist.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rigor/environment/rbs_collection_discovery.rb', line 57 def self.discover(lockfile_path:, project_root: Dir.pwd, auto_detect: true) resolved = resolve_lockfile_path( lockfile_path: lockfile_path, project_root: project_root, auto_detect: auto_detect ) return [] if resolved.nil? data = read_lockfile_yaml(resolved) return [] if data.nil? collection_root = resolve_collection_root(resolved, data) return [] unless collection_root.directory? gem_paths_from(collection_root, data) end |
.resolve_lockfile_path(lockfile_path:, project_root: Dir.pwd, auto_detect: true) ⇒ Object
Returns the resolved lockfile path (‘Pathname`) or `nil` when neither explicit nor auto-detect produces one. Public so the stats banner can surface what rigor found.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rigor/environment/rbs_collection_discovery.rb', line 77 def self.resolve_lockfile_path(lockfile_path:, project_root: Dir.pwd, auto_detect: true) if lockfile_path path = Pathname.new(File.(lockfile_path.to_s, project_root)) return path if path.file? return nil end return nil unless auto_detect candidate = Pathname.new(File.join(project_root, "rbs_collection.lock.yaml")) candidate.file? ? candidate : nil end |