Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using RVM with different gemsets in TextMate

Tags:

ruby

rvm

textmate

I have set up RVM and made individual gemsets for my projects as per the RVM best practices. Now running a test file in TextMate dosen't work and I have read here what to do. The problem is that it won't work because the guide expects me to have just one gemset (they call it "Rails3"). I normally have 2-3 projects open at a time (using different gemsets) so I can't effectively use this approach.

Have any of you solved that problem?

like image 468
jriff Avatar asked Feb 09 '11 18:02

jriff


People also ask

Should I use RVM or Rbenv?

While the versatility of RVM can be resourceful, when it comes to Ruby version management, it can be overkill. Using rbenv allows you to keep things simple and let other tools handle other aspects of the process. rbenv's primary focus on Ruby versioning leads to a more dev-friendly setup and configuration.

What are RVM and Gemsets?

RVM gives you compartmentalized independent ruby setups. This means that ruby, gems and irb are all separate and self-contained - from the system, and from each other. You may even have separate named gemsets. Let's say, for example, that you are testing two versions of a gem, with ruby 2.1. 1.

How do I add Gemset to RVM?

Step 1: rvm gemset create [name of gemset] Step 2: rvm --rvmrc [ruby version here]@[name of gemset] # Note: You can check your current ruby version by running "ruby -v" from your console. Step 3: Refresh your directory. # You can simply do this by checking out of your directory and going back to that directory again.


1 Answers

I've found the RVM wrappers method to be very buggy, and as you've discovered it doesn't work at all with gemsets unless you do a lot of tedious setup.

I've had some success using the following script as TM_RUBY:

#!/bin/bash

base_dir=${TM_PROJECT_DIRECTORY:-$PWD}
cd $base_dir
exec $MY_RUBY_HOME/bin/ruby $*

As long as you're in a TextMate project and you have a .rvmrc file in the project root it will run your code in the Ruby version and gemset specified in the .rvmrc. The cd makes sure RVM discovers the .rvmrc.

Put the code above into ~/bin/textmate_ruby_wrapper and then go to Preferences > Advanced > Shell Variables and set TM_RUBY to that same path.

like image 168
Theo Avatar answered Oct 14 '22 04:10

Theo