Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Gem::SpecFetcher#search_for_dependency
search_for_dependency(dependency, matching_platform = true, type: nil)
lib/rubygems/spec_fetcher.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems/spec_fetcher.rb, line 89
def search_for_dependency(dependency, matching_platform = true, type: nil)
found = {}
rejected_specs = {}
specs_type = type || dependency.identity
list, errors = available_specs(specs_type)
list.each do |source, specs|
if dependency.name.is_a?(String) && specs.respond_to?(:bsearch)
start_index = (0...specs.length).bsearch {|i| specs[i].name >= dependency.name }
end_index = (0...specs.length).bsearch {|i| specs[i].name > dependency.name }
specs = specs[start_index...end_index] if start_index && end_index
end
specs = specs.select {|tup| dependency.match?(tup) }
specs = decode_source_content_addressable_tuples(source, specs, latest: specs_type == :latest)
found[source] = specs.select do |tup|
if matching_platform && !Gem::Platform.match_gem?(tup.platform, tup.name)
pm = (
rejected_specs[dependency] ||= \
Gem::PlatformMismatch.new(tup.name, tup.version))
pm.add_platform tup.platform
false
elsif matching_platform && !ruby_abi_match?(tup)
false
else
true
end
end
end
errors += rejected_specs.values
tuples = []
found.each do |source, specs|
specs.each do |s|
tuples << [s, source]
end
end
tuples = tuples.sort_by {|x| x[0].version }
[tuples, errors]
end
Find and fetch gem name tuples that match dependency.
If matching_platform is false, gems for all platforms are returned.
type overrides the index type derived from dependency. See available_specs for the list of types.
See also
#detect
#spec_for_dependency
#decode_content_addressable_tuples
#suggest_gems_from_name
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0