class RBS::Repository
A repository object can handle multiple repository roots.
repo = RBS::Repository.new() repo.add(Pathname("vendor/rbs/gem-rbs")) repo.add(Pathname("vendor/rbs/internal-rbs")) repo.add(Pathname("vendor/rbs/definitely-rbs")) repo.lookup("minitest", "2.1.3") # => Pathname or nil
If one gem version can resolve to several directories, the last added dir wins.
Constants
- DEFAULT_STDLIB_ROOT
- VersionPath
Attributes
Public Class Methods
() → instance
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/repository.rb, line 83 def self.default new() end
(Gem::Version? version, Array[Gem::Version] candidates) → Gem::Version
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/repository.rb, line 87 def self.find_best_version(version, candidates) candidates = candidates.sort return candidates.last || raise unless version if v = candidates.reverse.bsearch {|v| v <= version ? true : false } v else candidates.first or raise end end
(?no_stdlib: bool) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/repository.rb, line 74 def initialize(no_stdlib: false) @dirs = [] @gems = {} unless no_stdlib add(DEFAULT_STDLIB_ROOT) end end
An optional keyword argument no_stdlib is to skip adding directory for stdlib classes. Passing truthy value will skip loading stdlib. (You can add the stdlib root by yourself.)
Public Instance Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/repository.rb, line 98 def add(dir) dirs << dir dir.each_child(false) do |child| gem_name = child.to_s gem_rbs = (gems[gem_name] ||= GemRBS.new(name: gem_name)) gem_rbs.paths << dir + child end end
Add new root dir to the repository set. If two repository dirs have exactly same gem-version definitions, the latter overwrites the prior.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/repository.rb, line 108 def lookup(gem, version) _, set = lookup_path(gem, version) set&.path end
Returns a directory for given gem name and version. version can be nil for any version.
If the given gem cannot be found, it returns nil.
(String gem, String? version) → [ GemRBS, VersionPath ]?
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/repository.rb, line 113 def lookup_path(gem, version) if gem_rbs = gems[gem] unless gem_rbs.empty? set = if version and v = Gem::Version.create(version)&.release gem_rbs.find_best_version(v) else gem_rbs.latest_version end [gem_rbs, set] end end end