Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Thor: Create new RVM gemsets by example for new Rails projects
# kate: syntax ruby;
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'rubygems'
require 'thor'
class Gemset < Thor
include Thor::Actions
desc "new GEMSET_NAME", "start a new gemset from another example gemset"
method_option :source, :default=>'new-project--rails3', :aliases=>'-s', :desc => 'rvm gemset to initialize the gemset. You need at least some gems like rails or hobo to create a project'
def new(target)
source=options.source
sdir= sh( source, "rvm gemset gemdir").strip
tdir= sh( target, "rvm gemset gemdir", true).strip
# puts "SOURCE=#{source} #{sdir}, TARGET=#{target} #{tdir}"
run "cp -a #{sdir}/* #{tdir}/"
end
desc "sh GEMSET_NAME, cmd", "run a command within a gemset"
def sh(name, cmd, create=false)
cmd= %Q{bash -lc "source $HOME/.rvm/scripts/rvm; rvm use #{create ? '--create' : ''} @#{name} >/dev/null && #{cmd}"}
puts cmd
answer = `#{cmd}`
# raise "gemset #{name} does not exist" if answer =~ /does not/
puts answer
answer
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment