Class: RBS::Repository
- Inherits:
-
Object
- Object
- RBS::Repository
- Defined in:
- lib/rbs/repository.rb
Defined Under Namespace
Classes: GemRBS
Constant Summary collapse
- DEFAULT_STDLIB_ROOT =
Pathname(_ = __dir__) + "../../stdlib"
- VersionPath =
_ = Struct.new(:gem, :version, :path, keyword_init: true)
Instance Attribute Summary collapse
-
#dirs ⇒ Object
readonly
Returns the value of attribute dirs.
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
Class Method Summary collapse
Instance Method Summary collapse
- #add(dir) ⇒ Object
-
#initialize(no_stdlib: false) ⇒ Repository
constructor
A new instance of Repository.
- #lookup(gem, version) ⇒ Object
- #lookup_path(gem, version) ⇒ Object
Constructor Details
#initialize(no_stdlib: false) ⇒ Repository
Returns a new instance of Repository.
74 75 76 77 78 79 80 81 |
# File 'lib/rbs/repository.rb', line 74 def initialize(no_stdlib: false) @dirs = [] @gems = {} unless no_stdlib add(DEFAULT_STDLIB_ROOT) end end |
Instance Attribute Details
#dirs ⇒ Object (readonly)
Returns the value of attribute dirs.
71 72 73 |
# File 'lib/rbs/repository.rb', line 71 def dirs @dirs end |
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
72 73 74 |
# File 'lib/rbs/repository.rb', line 72 def gems @gems end |
Class Method Details
.default ⇒ Object
83 84 85 |
# File 'lib/rbs/repository.rb', line 83 def self.default new() end |
.find_best_version(version, candidates) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File '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 |
Instance Method Details
#add(dir) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File '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 |
#lookup(gem, version) ⇒ Object
108 109 110 111 |
# File 'lib/rbs/repository.rb', line 108 def lookup(gem, version) _, set = lookup_path(gem, version) set&.path end |
#lookup_path(gem, version) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File '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 |