How to interact with RVM from ruby?
I am trying to get informations about the installed versions of ruby inside RVM and the associated gemsets and gems.
My first idea was to use a system call to rvm list
to get the installed Rubies and rvm use #{ruby_version} && rvm gemset list
for every Ruby. But there is an issue with that. It seems that rvm use #{ruby_version}
is executed and confirmed by RVM (output Using #{path_to_ruby
), but the gemsets listed are the one from the Ruby version that runs the scrip开发者_开发知识库t.
Is there any way to communicate with RVM from a Rubyscript via CLI or an API?
I'll take a stab at this - I think your problem is that rvm works mostly by mucking around with your environmental variables to point your shell to the different gemsets and ruby versions.
But when you run rvm use
in a subshell the changes of the env variables are not propagated up to the parent shell.
Without having looked into this too much yet, my initial idea would for you to run the rvm use
thing + then in that same subshell session run something that lists the contents of all these updated env vars (see here for which ones you need to look at: http://beginrescueend.com/rvm/info/ )...then in your ruby script you need to set the environment to match the environment in your subshell.
In shellspeak what you usually do in a case like this is "source" the script instead of executing it. I.e. source "the_script_that_sets_environment_variables"
. But when you are in a ruby script and use backticks to run stuff in a subshell you can't propagate the environment back up to the parent without doing it manually.
Another solution might be to take a look at the RVM Ruby API. I didn't find much documentation on it yet, but it might also do the trick for your case:
http://www.rubyflow.com/items/4285
精彩评论