So my good friend Adrien Thebo recommended I check out rvmrc files as a technique for project specific RVM settings. I wanted to see if I could produce gemsets specific to each project without the hassle of switching it myself all the time I change between projects.
So I started with a basic example. Lets start at the root of my dev area:
cd ~/Development
And I create a project called monstermash:
mkdir monstermash
cd monstermash
Now I need to create a .rvmrc file for this, but I specify a brand new gemset:
# rvm --rvmrc --create use ruby-1.8.7@monstermash
Using /Users/ken/.rvm/gems/ruby-1.8.7-p357 with gemset monstermash
Now there are two patterns already prepared for preserving what gem to use: bundler and gemset exports. Both reasonable choices but I'm going to use gemset export/import files for now since it needs very little setup. Bundler is a better choice probably when not everyone uses RVM.
So let me build up the monstermash gemset manually now by just installing particular gems:
gem install rspec --version 2.6.0
gem install json --version 1.6.2
gem install mocha --version 0.9.12
gem install jgrep --version 1.3.1
And then finally lets export them:
# rvm gemset export
Exporting current environments gemset to .gems
This saves the gemset in the local .gems file. Now I modify the created project .rvmrc in ~/Development/monstermash/.rvmrc and comment out the gemset area:
filename=".gems"
if [[ -s "$filename" ]]
then
rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
fi
Okay. To test, I cd back into my development area and specifically delete the gemset I just created:
# cd ~/Development
# rvm gemset delete monstermash
WARN: Are you SURE you wish to remove the entire gemset directory 'monstermash' (/Users/ken/.rvm/gems/ruby-1.8.7-p357@monstermash)?
(anything other than 'yes' will cancel) > yes
Now lets test if the rvmrc does the right thing by changing into the monstermash directory. As you can see I needed to 'trust' the file first, but this is only needed the first time you try to use it and every time it changes.
# cd monstermash
<snip>Big notice about trusting the file</snip>
Do you wish to trust this .rvmrc file? (/Users/ken/Development/monstermash/.rvmrc)
y[es], n[o], v[iew], c[ancel]> y
installing diff-lcs 1.1.3...
diff-lcs 1.1.3 installed.
installing jgrep 1.3.1...
jgrep 1.3.1 installed.
installing json 1.6.2...
json 1.6.2 installed.
installing rspec 2.6.0...
rspec 2.6.0 installed.
Using: /Users/ken/.rvm/gems/ruby-1.8.7-p357@monstermash
And there we go. Not only did it create the monstermash gemset, but it populated it from my projects .gems file:
# gem list
*** LOCAL GEMS ***
bundler (1.0.21)
diff-lcs (1.1.3)
jgrep (1.3.1)
json (1.6.4, 1.6.2)
rspec (2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
rspec-mocks (2.6.0)
Now whenever I cd into the directory, it does the right thing:
# cd ~/Development/monstermash
Using: /Users/ken/.rvm/gems/ruby-1.8.7-p357@monstermash
So in theory you could check-in the .rvmrc and .gems files into your VCS system so everyone could benefit from this. Of course, you'd want to make sure your project team was happy with this workflow as it only really benefits RVM uses.
No comments:
Post a Comment