Skip to content

Commit

Permalink
Newly generated gems require Ruby 2.6.0
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
okuramasafumi authored and hsbt committed Oct 9, 2021
1 parent 91f794b commit 7e50671
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 31 deletions.
31 changes: 28 additions & 3 deletions lib/bundler/cli/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run
: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)

Expand Down Expand Up @@ -166,11 +166,11 @@ def run
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
Expand Down Expand Up @@ -403,5 +403,30 @@ def ensure_safe_gem_name(name, constant_array)
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
2 changes: 1 addition & 1 deletion spec/bundler/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def create_temporary_dir(dir)
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
Expand Down
18 changes: 16 additions & 2 deletions spec/bundler/support/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,25 @@ def ruby_core_tarball?
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
Expand Down
21 changes: 11 additions & 10 deletions tool/bundler/rubocop_gems.rb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
31 changes: 16 additions & 15 deletions tool/bundler/standard_gems.rb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 7e50671

Please sign in to comment.