Module: Docscribe::Types::RBS::CollectionLoader

Defined in:
lib/docscribe/types/rbs/collection_loader.rb

Overview

Resolve the RBS collection directory from rbs_collection.lock.yaml.

After ‘bundle exec rbs collection install`, RBS writes a lock-file that records where gem signatures were installed. This loader reads that file so Docscribe can discover the collection directory automatically without requiring the user to pass –sig-dir manually.

Examples:

Typical lock-file structure

---
sources: [...]
path: ".gem_rbs_collection"
gems: [...]

Constant Summary collapse

LOCK_FILE =
'rbs_collection.lock.yaml'
DEFAULT_COLLECTION_PATH =
'.gem_rbs_collection'

Class Method Summary collapse

Class Method Details

.resolve(root: Dir.pwd) ⇒ String?

Note:

module_function: when included, also defines #resolve (instance visibility: private)

Resolve the installed RBS collection directory.

Returns nil when:

  • lock-file is absent (collection not initialized)

  • resolved directory does not exist on disk (collection not installed)

Parameters:

  • root (String) (defaults to: Dir.pwd)

    project root to search from

Returns:

  • (String, nil)

    absolute path to the collection directory, or nil



37
38
39
40
41
42
43
44
45
46
# File 'lib/docscribe/types/rbs/collection_loader.rb', line 37

def resolve(root: Dir.pwd)
  lock = Pathname(root).join(LOCK_FILE)
  return nil unless lock.file?

  data = YAML.safe_load(lock.read, permitted_classes: [Symbol]) || {}
  rel  = data['path'] || DEFAULT_COLLECTION_PATH

  resolved = Pathname(root).join(rel)
  resolved.directory? ? resolved.expand_path.to_s : nil
end