class Gem::Commands::InsturlCommand < Gem::Command def initialize super "insturl", "Install a gem from a URL" add_option("--git", "use `git clone' to fetch the URL") do |value, options| options[:git] = true end add_option("--force", "install even if already installed") do |value, options| options[:force] = true end end def description < 1 raise ArgumentError.new("multiple gemspecs found") end gemspec = gemspecs[0] # check if the same gem has been installed specobj = eval File.read(gemspec) unless options[:force] Gem::Specification.find_all do |spec| if spec.name == specobj.name and spec.version == specobj.version err = "#{spec.name} #{spec.version} has already been installed" raise ArgumentError.new(err) end end end # build gem return unless system("gem build #{gemspec}") # install gem gem = "#{specobj.name}-#{specobj.version}.gem" system("gem install #{gem}") end end # class Gem::Commands::InsturlCommand