diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2026-05-07 18:54:39 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-05-08 06:43:41 +0000 |
| commit | 54a07500ef98aac350afaa22fd06be5648807424 (patch) | |
| tree | 8b88a8399ed59843a1e696bf5256c81996d4c0be | |
| parent | 36b2ed2b129556bd76ffd4cad0fe750c4bbb4388 (diff) | |
[ruby/rubygems] Fall back from per-gem lookup to an :all override
Override.find_for now returns the per-gem entry when present and
otherwise the matching :all entry on the same field. This is the
single dispatch point for overrides in Definition and Resolver, so
the fallback is what wires :all into resolution and lockfile change
detection without further plumbing.
https://github.com/ruby/rubygems/commit/ef24b4eef9
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| -rw-r--r-- | lib/bundler/override.rb | 3 | ||||
| -rw-r--r-- | spec/bundler/bundler/override_spec.rb | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/bundler/override.rb b/lib/bundler/override.rb index 9d0db30d6a..ed5b51281f 100644 --- a/lib/bundler/override.rb +++ b/lib/bundler/override.rb @@ -5,7 +5,8 @@ module Bundler UPPER_BOUND_OPERATORS = ["<", "<="].freeze def self.find_for(overrides, name, field) - overrides.find {|o| o.target == name && o.field == field } + overrides.find {|o| o.target == name && o.field == field } || + overrides.find {|o| o.target == :all && o.field == field } end attr_reader :target, :field, :operation diff --git a/spec/bundler/bundler/override_spec.rb b/spec/bundler/bundler/override_spec.rb index e0ef4ed54d..78f7a62900 100644 --- a/spec/bundler/bundler/override_spec.rb +++ b/spec/bundler/bundler/override_spec.rb @@ -21,6 +21,22 @@ RSpec.describe Bundler::Override do it "returns nil for an empty overrides list" do expect(described_class.find_for([], "rails", :version)).to be_nil end + + it "falls back to an :all override on the same field" do + a = described_class.new(:all, :required_ruby_version, :ignore_upper) + expect(described_class.find_for([a], "rails", :required_ruby_version)).to be(a) + end + + it "prefers a per-gem override over a matching :all override" do + per_gem = described_class.new("rails", :required_ruby_version, ">= 3.4") + all_target = described_class.new(:all, :required_ruby_version, :ignore_upper) + expect(described_class.find_for([all_target, per_gem], "rails", :required_ruby_version)).to be(per_gem) + end + + it "does not fall back to :all when the field differs" do + a = described_class.new(:all, :required_ruby_version, :ignore_upper) + expect(described_class.find_for([a], "rails", :required_rubygems_version)).to be_nil + end end describe "#apply_to" do |
