Skip to content

Instantly share code, notes, and snippets.

@kivanio
Created April 30, 2009 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kivanio/104691 to your computer and use it in GitHub Desktop.
Save kivanio/104691 to your computer and use it in GitHub Desktop.
# Kivanio Barbosa
# Class to remove or install gems
class Phoda
attr_accessor :command
attr_accessor :file
attr_accessor :sudo
def initialize(command,file,sudo=false)
raise "Need some existent File." unless File.exist?(file)
@file = file
@command = command
@sudo = sudo
end
def vai
case @command
when "install"
instala_gems(carrega_file)
when "uninstall"
remove_gems(carrega_file)
else
"Don't know this command: #{@command}, try 'install' or 'uninstall'"
end
end
def instala_gems(gemas)
gemas.each do |gem|
p "installing #{gem}"
if @sudo
system("sudo gem install #{gem}")
else
system("gem install #{gem}")
end
end
end
def remove_gems(gemas)
gemas.each do |gem|
p "uninstalling #{gem}"
if @sudo
system("sudo gem uninstall #{gem}")
else
system("gem uninstall #{gem}")
end
end
end
def carrega_file
# put lines on Array
gemas=[]
linhas = File.readlines(@file).map {|l| l.rstrip}
linhas.select do |l|
gemas << l.split(/ /)[0]
end
gemas
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment