Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JHawk/622698 to your computer and use it in GitHub Desktop.
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
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