Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow suspenders to be used with a range of Ruby versions #1129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.5
3.2.2
13 changes: 13 additions & 0 deletions bin/suspenders
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ require 'pathname'
source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
$LOAD_PATH << source_path

require "suspenders/version"

ruby_version_range = Suspenders::RUBY_VERSION_RANGE.map do |version|
Gem::Version.new(version)
end

current_ruby_version = Gem::Version.new(RUBY_VERSION)

unless current_ruby_version.between?(*ruby_version_range)
abort "Your version of Ruby #{current_ruby_version} is not supported. " \
"Versions from #{ruby_version_range.map(&:to_s).join(" to ")} are supported."
end

activate_rails_version = ->(rails_version) do
rails_bin_path = Gem.activate_bin_path("railties", "rails", rails_version)
rails_path = File.expand_path("../..", rails_bin_path)
Expand Down
2 changes: 1 addition & 1 deletion lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def replace_gemfile
end

def ruby_version
create_file ".ruby-version", "#{Suspenders::RUBY_VERSION}\n"
create_file ".ruby-version", "#{RUBY_VERSION}\n"
end

def configure_i18n_for_missing_translations
Expand Down
9 changes: 5 additions & 4 deletions lib/suspenders/version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Suspenders
RAILS_VERSION = "~> 7.0.0".freeze
RUBY_VERSION = IO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing something: we're no longer setting RUBY_VERSION, but we still reference it from elsewhere (e.g. app_builder.rb).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mike-burns Yeah, that can be confusing. It turns out RUBY_VERSION is a global/default Ruby constant, and we were overriding it. It says which Ruby version is running. The idea is to use the global constant to set up generated applications, as long as it is within the allowed range. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, that's what I was missing. Thanks for the reminder -- yes, RUBY_VERSION!

.read("#{File.dirname(__FILE__)}/../../.ruby-version")
.strip
.freeze

minimum_ruby_version = "3.0.5"
maximum_ruby_version = Pathname(__dir__).join("../../.ruby-version").read.strip

RUBY_VERSION_RANGE = [minimum_ruby_version, maximum_ruby_version].freeze
VERSION = "20230113.0".freeze
end
6 changes: 3 additions & 3 deletions spec/features/new_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
it "uses custom Gemfile" do
gemfile_file = IO.read("#{project_path}/Gemfile")
expect(gemfile_file).to match(
/^ruby "#{Suspenders::RUBY_VERSION}"$/o
/^ruby "#{RUBY_VERSION}"$/o
)
expect(gemfile_file).to match(
/^gem "rails", "#{Suspenders::RAILS_VERSION}"$/o
Expand All @@ -34,8 +34,8 @@
end
end

it "creates .ruby-version from Suspenders .ruby-version" do
ruby_version_file = IO.read("#{project_path}/.ruby-version")
it "creates .ruby-version with the running ruby version" do
ruby_version_file = project_path.join(".ruby-version").read

expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
end
Expand Down
4 changes: 3 additions & 1 deletion suspenders.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ require "suspenders/version"
require "date"

Gem::Specification.new do |s|
s.required_ruby_version = ">= #{Suspenders::RUBY_VERSION}"
minimum_ruby_version, maximum_ruby_version = Suspenders::RUBY_VERSION_RANGE

s.required_ruby_version = [">= #{minimum_ruby_version}", "<= #{maximum_ruby_version}"]
s.required_rubygems_version = ">= 3.0.0"
s.authors = ["thoughtbot"]

Expand Down
2 changes: 1 addition & 1 deletion templates/Gemfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end

ruby "<%= Suspenders::RUBY_VERSION %>"
ruby <%= RUBY_VERSION.inspect %>

<% if options[:api] %>
gem "sprockets", "< 4"
Expand Down
Loading