1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Refactor Bundler::Dsl#check_rubygems_source_safety to improve readability

`check_rubygems_source_safety` is responsible for:

1. if there are multiple global sources
  - for bundle 3.x raise an error
  - for bundle 2.x print a warning
2. print a warning if there is no explicit global source

The second responsibility was added recently and now the logic could be
extracted to improve readability. Conditions are still live in the `check_rubygems_source_safety` method
since we don't want to call both functions always and that would help us achieve that.

https://github.com/rubygems/rubygems/commit/f3d7e946ee
This commit is contained in:
Daniel Niknam 2021-07-25 00:42:24 +10:00 committed by Hiroshi SHIBATA
parent 1ef360230e
commit 49176e8c8c
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 12 additions and 6 deletions

View file

@ -448,14 +448,20 @@ repo_name ||= user_name
def check_rubygems_source_safety
if @sources.implicit_global_source?
Bundler::SharedHelpers.major_deprecation 2, "This Gemfile does not include an explicit global source. " \
"Not using an explicit global source may result in a different lockfile being generated depending on " \
"the gems you have installed locally before bundler is run." \
"Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"."
implicit_global_source_warning
elsif @sources.aggregate_global_source?
multiple_global_source_warning
end
end
return unless @sources.aggregate_global_source?
def implicit_global_source_warning
Bundler::SharedHelpers.major_deprecation 2, "This Gemfile does not include an explicit global source. " \
"Not using an explicit global source may result in a different lockfile being generated depending on " \
"the gems you have installed locally before bundler is run." \
"Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"."
end
def multiple_global_source_warning
if Bundler.feature_flag.bundler_3_mode?
msg = "This Gemfile contains multiple primary sources. " \
"Each source after the first must include a block to indicate which gems " \

View file

@ -245,7 +245,7 @@ RSpec.describe Bundler::Dsl do
describe "#check_primary_source_safety" do
context "when a global source is not defined implicitly" do
it "will raise a major deprecation warning" do
not_a_global_source = double("not-a-global-source", no_remotes?: true, multiple_remotes?: false)
not_a_global_source = double("not-a-global-source", :no_remotes? => true)
allow(Bundler::Source::Rubygems).to receive(:new).and_return(not_a_global_source)
warning = "This Gemfile does not include an explicit global source. " \