mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Implement Rubygem::install
Use the code of `gem-install` command as a basis. Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
parent
3c60ee88e5
commit
4c56c73e9d
2 changed files with 22 additions and 14 deletions
|
@ -16,19 +16,9 @@ class Pry
|
|||
end
|
||||
|
||||
def process(gem)
|
||||
begin
|
||||
destination = File.writable?(Gem.dir) ? Gem.dir : Gem.user_dir
|
||||
installer = Gem::DependencyInstaller.new :install_dir => destination
|
||||
installer.install gem
|
||||
rescue Errno::EACCES
|
||||
raise CommandError, "Insufficient permissions to install `#{text.green gem}`."
|
||||
rescue Gem::GemNotFoundException
|
||||
raise CommandError, "Gem `#{text.green gem}` not found."
|
||||
else
|
||||
Gem.refresh
|
||||
output.puts "Gem `#{text.green gem}` installed."
|
||||
require gem
|
||||
end
|
||||
Rubygem.install(gem)
|
||||
output.puts "Gem `#{ text.green(gem) }` installed."
|
||||
require gem
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
require 'rubygems'
|
||||
|
||||
class Pry
|
||||
module Rubygem
|
||||
|
||||
class << self
|
||||
def installed?(name)
|
||||
require 'rubygems'
|
||||
if Gem::Specification.respond_to?(:find_all_by_name)
|
||||
Gem::Specification.find_all_by_name(name).any?
|
||||
else
|
||||
|
@ -50,6 +51,23 @@ class Pry
|
|||
self.list.map(&:name)
|
||||
end
|
||||
end
|
||||
|
||||
# Installs a gem with all its dependencies.
|
||||
#
|
||||
# @param [String] name
|
||||
# @return [void]
|
||||
def install(name)
|
||||
destination = File.writable?(Gem.dir) ? Gem.dir : Gem.user_dir
|
||||
installer = Gem::DependencyInstaller.new(:install_dir => destination)
|
||||
installer.install(name)
|
||||
rescue Errno::EACCES
|
||||
raise CommandError,
|
||||
"Insufficient permissions to install `#{ text.green(name) }`."
|
||||
rescue Gem::GemNotFoundException
|
||||
raise CommandError, "Gem `#{ text.green(name) }` not found."
|
||||
else
|
||||
Gem.refresh
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue