Created
October 12, 2010 18:48
-
-
Save JHawk/622698 to your computer and use it in GitHub Desktop.
Rakefile to install a gem and copy it to my Documents dir so I can play with it - run as sudo like: sudo rake G=bundler,nokogiri,rails --trace
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
require 'rubygems' | |
require 'rake' | |
require 'fileutils' | |
desc "installs and copies gems to Documents for src code inspection - just type sudo rake G=gem1,gem2,gem3..." | |
task :default => :gem_cp | |
task :gem_cp do | |
class Doppleganger | |
def initialize(gems) | |
@gems = gems | |
@source_path = "#{Gem.path[1]}/gems/" | |
@username = `who`.split(" ")[0] | |
@destination_path = "/home/#{@username}/Documents/gems/" | |
end | |
def gem_with_version(line) | |
match = line.match(/[A-Za-z_-]+[-]+[\d.]{2,}/) | |
match[0] if match | |
end | |
def install_with_dependencies(gem) | |
puts output = `gem install #{gem}` | |
output.split("Successfully").map {|s| gem_with_version(s)}.compact | |
end | |
def copy_for_inspection(gem) | |
source = @source_path + gem + '/' | |
destination = @destination_path + gem + '/' | |
cp_r source, @destination_path, :verbose => true | |
chown_R @username, @username, destination, :verbose => true | |
end | |
def dopplepopolis # you know... Sealab!? | |
@gems.split(',').each do |gem| | |
install_with_dependencies(gem).map {|g| copy_for_inspection(g)} | |
end | |
end | |
end | |
gems = ENV['G'] || ENV['GEMS'] | |
raise ArgumentError, "No gems list. Add GEMS=gem1,gem2,gem3..." unless gems | |
Doppleganger.new(gems).dopplepopolis | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment