summaryrefslogtreecommitdiff
path: root/lib/rubygems/spec_fetcher.rb
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2020-03-24 07:39:24 +0100
committer<[email protected]>2020-03-24 15:39:24 +0900
commit96064e6f1ce100a37680dc8f9509f06b3350e9c8 ()
tree798b59f015cb82ee3cd0427f80584032175829ba /lib/rubygems/spec_fetcher.rb
parent930b012ad96bfb0bd12446b89407120744ef92eb (diff)
Sync rubygems with current master (#2889)
Notes: Merged-By: hsbt <[email protected]>
-rw-r--r--lib/rubygems/spec_fetcher.rb23
1 files changed, 13 insertions, 10 deletions
@@ -171,30 +171,33 @@ class Gem::SpecFetcher
# Suggests gems based on the supplied +gem_name+. Returns an array of
# alternative gem names.
- def suggest_gems_from_name(gem_name, type = :latest)
gem_name = gem_name.downcase.tr('_-', '')
max = gem_name.size / 2
names = available_specs(type).first.values.flatten(1)
matches = names.map do |n|
next unless n.match_platform?
-
- distance = levenshtein_distance gem_name, n.name.downcase.tr('_-', '')
-
- next if distance >= max
-
- return [n.name] if distance == 0
-
- [n.name, distance]
end.compact
matches = if matches.empty? && type != :prerelease
suggest_gems_from_name gem_name, :prerelease
else
matches.uniq.sort_by { |name, dist| dist }
end
- matches.first(5).map { |name, dist| name }
end
##