Created
August 20, 2012 13:08
-
-
Save umuro/3403866 to your computer and use it in GitHub Desktop.
Thor: Create new RVM gemsets by example for new Rails projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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