Skip to content

Instantly share code, notes, and snippets.

@umuro
Created August 20, 2012 13:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umuro/3403866 to your computer and use it in GitHub Desktop.
Save umuro/3403866 to your computer and use it in GitHub Desktop.
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