Newly generated gems require Ruby 2.6.0

In 2021, Ruby 2.5 and older are EOL.
We can set the default required Ruby version to 2.6.0 to
encourage people to use newer Ruby.
If the command is executed with old Ruby, it falls back to 2.3.0.
It's still possible to create a gem for older Ruby just by changing
two lines of code (one in gemspec and another is in rubocop.yml).
This commit is contained in:
OKURA Masafumi 2021-09-20 23:18:14 +09:00 коммит произвёл Hiroshi SHIBATA
Родитель 91f794b516
Коммит 7e506716d2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F9CF13417264FAC2
5 изменённых файлов: 72 добавлений и 31 удалений

Просмотреть файл

@ -68,7 +68,7 @@ module Bundler
:bundler_version => bundler_dependency_version,
:git => use_git,
:github_username => github_username.empty? ? "[USERNAME]" : github_username,
:required_ruby_version => Gem.ruby_version < Gem::Version.new("2.4.a") ? "2.3.0" : "2.4.0",
:required_ruby_version => required_ruby_version,
}
ensure_safe_gem_name(name, constant_array)
@ -166,11 +166,11 @@ module Bundler
config[:linter] = ask_and_set_linter
case config[:linter]
when "rubocop"
config[:linter_version] = Gem.ruby_version < Gem::Version.new("2.4.a") ? "0.81.0" : "1.7"
config[:linter_version] = rubocop_version
Bundler.ui.info "RuboCop enabled in config"
templates.merge!("rubocop.yml.tt" => ".rubocop.yml")
when "standard"
config[:linter_version] = Gem.ruby_version < Gem::Version.new("2.4.a") ? "0.2.5" : "1.0"
config[:linter_version] = standard_version
Bundler.ui.info "Standard enabled in config"
templates.merge!("standard.yml.tt" => ".standard.yml")
end
@ -403,5 +403,30 @@ module Bundler
def open_editor(editor, file)
thor.run(%(#{editor} "#{file}"))
end
def required_ruby_version
if Gem.ruby_version < Gem::Version.new("2.4.a") then "2.3.0"
elsif Gem.ruby_version < Gem::Version.new("2.5.a") then "2.4.0"
elsif Gem.ruby_version < Gem::Version.new("2.6.a") then "2.5.0"
else
"2.6.0"
end
end
def rubocop_version
if Gem.ruby_version < Gem::Version.new("2.4.a") then "0.81.0"
elsif Gem.ruby_version < Gem::Version.new("2.5.a") then "1.12"
else
"1.21"
end
end
def standard_version
if Gem.ruby_version < Gem::Version.new("2.4.a") then "0.2.5"
elsif Gem.ruby_version < Gem::Version.new("2.5.a") then "1.0"
else
"1.3"
end
end
end
end

Просмотреть файл

@ -569,7 +569,7 @@ RSpec.describe "bundle gem" do
it "sets a minimum ruby version" do
bundle "gem #{gem_name}"
expect(generated_gemspec.required_ruby_version).to eq(Gem::Requirement.new(Gem.ruby_version < Gem::Version.new("2.4.a") ? ">= 2.3.0" : ">= 2.4.0"))
expect(generated_gemspec.required_ruby_version.to_s).to start_with(">=")
end
it "requires the version file" do

Просмотреть файл

@ -283,11 +283,25 @@ module Spec
end
def rubocop_gemfile_basename
source_root.join("tool/bundler/#{RUBY_VERSION.start_with?("2.3") ? "rubocop23_gems.rb" : "rubocop_gems.rb"}")
filename = if RUBY_VERSION.start_with?("2.3")
"rubocop23_gems"
elsif RUBY_VERSION.start_with?("2.4")
"rubocop24_gems"
else
"rubocop_gems"
end
source_root.join("tool/bundler/#{filename}.rb")
end
def standard_gemfile_basename
source_root.join("tool/bundler/#{RUBY_VERSION.start_with?("2.3") ? "standard23_gems.rb" : "standard_gems.rb"}")
filename = if RUBY_VERSION.start_with?("2.3")
"standard23_gems"
elsif RUBY_VERSION.start_with?("2.4")
"standard24_gems"
else
"standard_gems"
end
source_root.join("tool/bundler/#{filename}.rb")
end
extend self

Просмотреть файл

@ -4,12 +4,12 @@ GEM
ast (2.4.2)
diff-lcs (1.4.4)
minitest (5.14.4)
parallel (1.19.2)
parser (3.0.1.0)
parallel (1.21.0)
parser (3.0.2.0)
ast (~> 2.4.1)
power_assert (2.0.0)
power_assert (2.0.1)
rainbow (3.0.0)
rake (13.0.3)
rake (13.0.6)
rake-compiler (1.1.1)
rake
regexp_parser (2.1.1)
@ -27,25 +27,26 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.12.1)
rubocop (1.21.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
test-unit (3.4.0)
test-unit (3.4.7)
power_assert
unicode-display_width (2.0.0)
unicode-display_width (2.1.0)
PLATFORMS
arm64-darwin-20
universal-java-11
x86_64-darwin-19
x86_64-linux
DEPENDENCIES

Просмотреть файл

@ -4,12 +4,12 @@ GEM
ast (2.4.2)
diff-lcs (1.4.4)
minitest (5.14.4)
parallel (1.19.2)
parser (3.0.1.0)
parallel (1.21.0)
parser (3.0.2.0)
ast (~> 2.4.1)
power_assert (2.0.0)
power_assert (2.0.1)
rainbow (3.0.0)
rake (13.0.3)
rake (13.0.6)
rake-compiler (1.1.1)
rake
regexp_parser (2.1.1)
@ -27,31 +27,32 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.11.0)
rubocop (1.20.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-performance (1.10.1)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
rubocop-performance (1.11.5)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
standard (1.0.4)
rubocop (= 1.11.0)
rubocop-performance (= 1.10.1)
test-unit (3.4.0)
standard (1.3.0)
rubocop (= 1.20.0)
rubocop-performance (= 1.11.5)
test-unit (3.4.7)
power_assert
unicode-display_width (2.0.0)
unicode-display_width (2.1.0)
PLATFORMS
arm64-darwin-20
universal-java-11
x86_64-darwin-19
x86_64-linux
DEPENDENCIES