diff options
author | Ellen Marie Dash <[email protected]> | 2024-10-31 19:56:55 -0400 |
---|---|---|
committer | git <[email protected]> | 2024-11-26 22:04:26 +0000 |
commit | 092a48de7ef905e393abe3369a37e558333a5039 (patch) | |
tree | cc094fb236983cb33db45e21b03f254acd7618bd /lib/rubygems | |
parent | 8f9b9aecd04c4fa2bc9d15de4dfb3c6105e97b49 (diff) |
[rubygems/rubygems] [SpecFetcher] If candidates include {name}-ruby or ruby-{name}, recommend those.
https://github.com/rubygems/rubygems/commit/d7d33172c1
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/spec_fetcher.rb | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index cf92dd73ee..285f117b39 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -182,20 +182,31 @@ class Gem::SpecFetcher min_length = gem_name.length - max max_length = gem_name.length + max + gem_name_with_postfix = "#{gem_name}ruby" + gem_name_with_prefix = "ruby#{gem_name}" + matches = names.filter_map do |n| 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 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? + # If the length is min_length or shorter, we've done `max` deletions. + # This would be rejected later, so we skip it for performance. + next if len <= min_length + # The candidate name, normalized the same as gem_name. normalized_name = n.name.downcase normalized_name.tr!("_-", "") + # If the gem is "{NAME}-ruby" and "ruby-{NAME}", we want to return it. + # But we already removed hyphens, so we check "{NAME}ruby" and "ruby{NAME}". + next [n.name, 0] if normalized_name == gem_name_with_postfix + next [n.name, 0] if normalized_name == gem_name_with_prefix + + # If the length is max_length or longer, we've done `max` insertions. + # This would be rejected later, so we skip it for performance. + next if len >= max_length + # 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. |