diff options
author | Ellen Marie Dash <[email protected]> | 2024-09-28 14:26:13 -0400 |
---|---|---|
committer | git <[email protected]> | 2024-10-23 20:03:13 +0000 |
commit | fe66eee1a01eea711baa1d750424ed6624e38b37 (patch) | |
tree | 35281557cae2d49c74946c09147f18ebabfeba2a | |
parent | 35f0b7c83fbeac0fa13df253b90aea5919715a7f (diff) |
[rubygems/rubygems] Document suggest_gems_from_name()
https://github.com/rubygems/rubygems/commit/8f9983cc21
-rw-r--r-- | lib/rubygems/spec_fetcher.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index d6dd59e4bd..946e327ec8 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -181,13 +181,23 @@ class Gem::SpecFetcher len = n.name.length # If the length is min_length or shorter, we've done `max` deletions. # If the length is max_length or longer, we've done `max` insertions. - # These would both be rejected later, so we bail early for performance. + # These would both be rejected later, so we skip early for performance. next if len <= min_length || len >= max_length + + # If the gem doesn't support the current platform, bail early. next unless n.match_platform? distance = levenshtein_distance gem_name, n.name.downcase.tr("_-", "") + + # Edit distance is greater than the maximum we allow, so skip this result. next if distance >= max + + # If we found an exact match (after stripping underscores and hyphens), + # that's our most likely candidate. + # Return it immediately, and skip the rest of the loop. return [n.name] if distance == 0 + + # If all else fails, return the name and the calculated distance. [n.name, distance] end.compact |