search_for_dependency(dependency, matching_platform=true)
public
Find and fetch gem name tuples that match
dependency.
If matching_platform is false, gems for all platforms are
returned.
Show source
def search_for_dependency(dependency, matching_platform=true)
found = {}
rejected_specs = {}
if dependency.prerelease?
if dependency.specific?
type = :complete
else
type = :abs_latest
end
elsif dependency.latest_version?
type = :latest
else
type = :released
end
list, errors = available_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
found[source] = specs.select do |tup|
if dependency.match?(tup)
if matching_platform and !Gem::Platform.match(tup.platform)
pm = (
rejected_specs[dependency] ||= Gem::PlatformMismatch.new(tup.name, tup.version))
pm.add_platform tup.platform
false
else
true
end
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] }
return [tuples, errors]
end