Skip to content

Instantly share code, notes, and snippets.

@glurp
Created March 15, 2012 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glurp/2043077 to your computer and use it in GitHub Desktop.
Save glurp/2043077 to your computer and use it in GitHub Desktop.
auto gem install
module Kernel
def ruiby_require(*gems)
w=Ruiby_dialog.new
gems.flatten.each do|gem|
begin
require gem
rescue LoadError => e
rep=w.ask("<em>Loading #{gems.join(', ')}</em>\n\n'#{gem}' package is missing. Can I load it from internet ?")
exit! unless rep
require 'open3'
w.log("gem install #{gem} --no-ri --no-rdoc")
Gtk.main_iteration while Gtk.events_pending?
Open3.popen3("gem install #{gem}") { |si,so,se|
q=Queue.new
Thread.new { loop {q.push(so.gets) } rescue nil; q.push(nil)}
Thread.new { loop {q.push(se.gets) } rescue nil; q.push(nil)}
str=""
while str
timeout(1) { str=q.pop } rescue nil
(w.log(str);str="") if str && str.size>0
Ruiby.update
end
}
w.log "done!"
Ruiby.update
Gem.clear_paths()
require(gem)
w.log("loading '#{gem}' ok!")
end
end
w.destroy()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment