Sublime Forum

Building Ruby and using RVM

#1

I’m playing with the Ray library which I’ve installed into my RVM environment.

When I try to build it in Sublime Text 2, I get an error that it can’t find Ray. Launching it from Terminal is just fine.

I don’t think it’s seeing the RVM environment?

0 Likes

Laundry List
#2

I think a better way of asking is: How do I make ST2 use the ruby set by RVM?

Am I the only one running into this?

0 Likes

#3

I have the same issue, the trick is going to be using $MY_RUBY_HOME in Ruby.sublime-build. I’ll post back if I have any success.

Some docs:

sublimetext.com/docs/build

sublimetext.info/docs/en/referen … stems.html

0 Likes

#4

I wasn’t able to get $MY_RUBY_HOME working. My solution was to insert the full path to my RVM bin dir inside my Ruby.sublime-build:

{ "cmd": "/Users/alex/.rvm/bin/ruby", "-cw", "$file"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.ruby" }

Note that I’m using the Build command to check syntax, not to run the file, so I’m using the “-cw” flags. (I’m using a hacked RubyTest plugin to run.)

Question: should I put this inside Packages/Ruby/Ruby.sublime-build or Packages/User/Ruby.sublime-build ?

0 Likes

#5

Thanks for the answer!

I put my in Packages/User/Ruby-RVM.sublime-build just so it doesn’t clash with any defaults.

0 Likes

#6

@forehead How are you getting RubyTest to work? Whenever I run it I get ‘/bin/sh: rspec: command not found’. It works fine from the command line though. Any ideas?

0 Likes

#7

@n00ge here’s my RubyTest.sublime-settings, in which i had to put the full paths to my exes.

{ "ruby_unit_exec": "/Users/alex/.rvm/bin/ruby -Itest", "ruby_cucumber_exec": "cucumber", "ruby_rspec_exec": "/Users/alex/.rvm/bin/rvm 1.9.2 exec bundle exec rspec" }

Yes, it’s annoying. :wink:

0 Likes

#8

@dsr if you put settings in Ruby-RVM.sublime-build, then how do they get loaded? I’m fuzzy on how ST2 makes the mapping between file name and build system…

And along those lines, I’d like to have one build system (i.e. “command that gets run when I hit cmd-B”) for .rb files, another for _test.rb files, and yet another for _spec.rb files. Any ideas on how to get that kludged up?

0 Likes

#9

I manually select the build from the menu item. I’m not sure how you would map it to automatically select it for all .rb files.

0 Likes

#10

Last I remember, I think @jps broke up the extensions by periods. I’m not sure if looking for _spec.rb would be possible but it would certainly be handy. Maybe he can verify.

0 Likes

#11

Just for reference, this is how I got TextMate to run my current directory’s rvm beginrescueend.com/integration/textmate/

So rather than pointing Sublime at /Users/alex/.rvm/bin/rvm 1.9.2 or /Users/alex/.rvm/bin/ruby you could do /Users/youruser/.rvm/bin/rvm-auto-ruby and it would rvm’s default ruby version (that you might need to change if you never have since it would probably be whatever shipped with your pc - for macs it’d be 1.8.7). Sublime would use the default version, I think, because it does not have a context of a directory so it wouldn’t locate your project’s .rvmrc file. If someone could figure that part out, it’d be great because you wouldn’t have to worry about what gemsets or ruby versions you’re using.

Here is the rvm-auto-ruby script

#!/usr/bin/env bash

true ${rvm_scripts_path:="$rvm_path/scripts"}
true ${rvm_environments_path:="$rvm_path/environments"}

if  -n "$rvm_path" && -s "$rvm_scripts_path/rvm" ]]; then
  source "$rvm_scripts_path/rvm" > /dev/null 2>&1

elif  -s "$HOME/.rvm/scripts/rvm" ]]; then
  source "$HOME/.rvm/scripts/rvm" > /dev/null 2>&1

elif  -s "/usr/local/rvm/scripts/rvm" ]]; then
  source "/usr/local/rvm/scripts/rvm" > /dev/null 2>&1

else
  echo "Unable to detect rvm, please manually set the rvm_path env variable." >&2
  exit 1
fi

 -s "$rvm_environments_path/default" ]] && source "$rvm_environments_path/default"

rvm_promptless=1 rvm rvmrc load > /dev/null 2>&1

exec ruby "$@"
0 Likes