Take rbenv_ruby_version from .ruby-version file by default
uxxman opened this issue Β· comments
It is a common convention in rbenv (even rvm) projects to define .ruby-version file for the project to automatically switch to the right ruby version. Rails projects also generates this file for you by default. So, instead of setting this value at 2 different places and risking them to get out of sync during an upgrade, can we make the default value of rbenv_ruby_version to consider .ruby-version file if it exists? For example
Line 8 in 4734946
with
rbenv_ruby_version: File.exist?(".ruby-version") ? File.read(".ruby-version").strip : nil
I think this could work. In fact, tomo does something similar for bundler where if bundler_version
is nil
, it will read the bundler version from the Gemfile.lock
:
tomo/lib/tomo/plugin/bundler/tasks.rb
Line 32 in 4734946
Generally speaking I try to avoid that kind of magic, though. Different deployment tools use different files. Heroku, for example, looks for a ruby
declaration inside the Gemfile
and does not use .ruby-version
. So that inconsistent magic might confuse people.
But, considering that rails new
generates a .ruby-version
by default, this does seem reasonable. So I am willing to try it.
I guess that means that going forward, tomo init
would no longer automatically put the Ruby version in the .tomo/config.yml
file for you? In other words, we'd remove this line:
tomo/lib/tomo/templates/config.rb.erb
Line 17 in 4734946
In terms of reading the .ruby-version
file, I think that needs to be done server-side. Because you want the version of Ruby installed to match the code that is being deployed, not what you have locally. In some cases they might be different; e.g. if you have the develop
branch checked out locally but you are asking tomo to deploy main
.
So something like the bundler plugin does server-side:
tomo/lib/tomo/plugin/bundler/tasks.rb
Lines 53 to 65 in 4734946
Does that sound right?
If you want to put together a PR, feel free to give it a shot. I'd appreciate more contributors. π
I guess that means that going forward,
tomo init
would no longer automatically put the Ruby version in the.tomo/config.yml
file for you? In other words, we'd remove this line:
Exactly π One less config to worry about π
In terms of reading the
.ruby-version
file, I think that needs to be done server-side. Because you want the version of Ruby installed to match the code that is being deployed, not what you have locally. In some cases they might be different; e.g. if you have thedevelop
branch checked out locally but you are asking tomo to deploymain
.
Again agreed π They can surely differ in some scenarios and the server side value is important, not the local one.
If you want to put together a PR, feel free to give it a shot. I'd appreciate more contributors. π
Sure, would love to β€οΈ I will checkout the code in bundler plugin and try to put together a PR using something similar for rbenv ruby version config π
Thanks for the merge π π closing the issue