-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
Use Gem::Version to compare versions #1236
base: main
Are you sure you want to change the base?
Conversation
File.open("test/dummy/Gemfile", "w") do |gemfile| | ||
gemfile.write('source "https://rubygems.org"') | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While working in this file, if nothing was raised when a run_generator
command ran, then there was a big slowdown and the following message would appear multiple times:
...[DEPRECATED] 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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding source "https://rubygems.org"
to the Gemfile
resolved this warning, making it easier to test the tests in the file.
Note that run_generator
still fails for different reasons, but it's a faster fail with less noise.
return if version.blank? | ||
|
||
Gem::Version.new(version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think these two lines are clearer as written or combined like this?
Gem::Version.new(version) unless version.blank?
end | ||
|
||
def node_not_installed? | ||
!node_version.present? | ||
node_version.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to avoid the double negative of not_installed
and
!(...).present?
.
483c690
to
b0015d3
Compare
[DEPRECATED] 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".
Simplify writing of source to Gemfile
b0015d3
to
579a24d
Compare
version = ENV["NODE_VERSION"] || `node --version`[/\d+\.\d+\.\d+/] | ||
|
||
return if version.blank? | ||
|
||
Gem::Version.new(version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the following work?
version = ENV["NODE_VERSION"] || `node --version`[/\d+\.\d+\.\d+/] | |
return if version.blank? | |
Gem::Version.new(version) | |
if version = ENV.fetch(ENV["NODE_VERSION"], `node --version`[/\d+\.\d+\.\d+/]) | |
Gem::Version.new(version) | |
else | |
"" | |
end |
It solves a couple of issues.
- Deals with
#[]
returning something falsy but not nil - Gets rid of the trailing conditional and makes the method more idiomatic
- Ensures the method always returns a string
This PR:
WebGeneratorTest
String comparison of version numbers can produce incorrect results. For example,
"20.10.0" < "20.2.0"
resolves totrue
.