Backgound
A little background to this question first: Ruby on Rails has some security issues as of late. So we need to update the Rails version on our projects. If you have a few, that gets old fast if you do it by hand… So I figured I can create a Thor task for this.
Question
This now works great! BUT! I need to respect the .rvmrc file for each project while installing the new versions of rails. I want this script to be OpenSourced soon, but I want to tacle the problem of not respecting the .rvmrc file first.
So what I need is a way of using the right RVM ruby version/gemset when I change to a directory to update the Rails version.
How is the way for this to be done? Can it be done from the Ruby script in a way so that it works on Mac and Linux, regardless of Shell (found a answer with zsh support, but what about all the other shells out there?)
Quick Example code:
#Scan the base directory down for Gemfiles
gem_files = File.join("**", "Gemfile")
Dir.glob(gem_files){|gemfile|
project_folder = File.dirname(gemfile)
puts "Found Gemfile in #{project_folder}"
Dir.chdir(project_folder) do
#TODO: Respect/load the rvmrc file in this directory
update_gem_file(project_folder) #example
run 'bundle update rails' #<--- needs to be done in the RVM gemset
end
}
Just to give you an idea of what I’m trying to do.
Check out this project https://github.com/versapay/bundler-auto-update it basically:
As for RVM use this simple code:
You can find more details on scripting with RVM on https://rvm.io