Sometimes you want just to tweak the way you run a Rails project, but without commit those changes upstream.
There are some tools that allow one to do it without much problem.
Direnv is your Ally
Dir env allows you to just ignore the rbenv .ruby-version or asdf .tool-version in a very easy way. For example if the project uses a ruby version 2.7.1 but you have installed the version 2.7.2, all you need to do is to put this on your .envrc file:
load_prefix $HOME/.asdf/installs/ruby/2.7.2
layout ruby
With this, you can force the version 2.7.2 upon the Project.
Gemfile manipulation
Imagine that the Project mandates you to use Passenger, but you want to run the project locally using Puma, but without commit it to the original Gemfile. One way to do it is just to create a Gemfile.local with:
eval_gemfile "Gemfile"
gem 'passenger', require: false
gem 'puma'
After it just, copy the original Gemfile.lock to Gemfile.local.lock and place add more one line to your .envrc file:
# what we add previously
load_prefix $HOME/.asdf/installs/ruby/2.7.2
layout ruby
# a new bundle gemfile
BUNDLE_GEMFILE=Gemfile.local
With this in place, just run the commands as usual:
bundle install
bundle exec rails server puma
Aditional notes
- It's important to always resync the
Gemfile.local.lockwhen some major modification on the originalGemfile.lockhappens. - It's important to make sure that your
.gitignore_globalfile will ignore properly the.envrcandGemfile.localandGemfile.local.lockfiles.
Top comments (1)
Me too. This technique is really usefull, and it's is surprising to not see more posts about it.