Skip to content

Commit

Permalink
Command::InstallCommand: honor ".gemrc" switches
Browse files Browse the repository at this point in the history
Fix issue #666 (install-command doesn't seem to honor gemrc)

Also, prettify various messages from "install-command".
  • Loading branch information
kyrylo committed Feb 23, 2013
1 parent 68ac45f commit 074fe0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
21 changes: 9 additions & 12 deletions lib/pry/commands/install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,31 @@ def process(name)
command = find_command(name)

if command_dependencies_met?(command.options)
output.puts "Dependencies for #{command.name} are met. Nothing to do."
output.puts "Dependencies for #{ text.green(name) } are met. Nothing to do"
return
end

output.puts "Attempting to install `#{name}` command..."
output.puts "Attempting to install #{ text.green(name) } command..."
gems_to_install = Array(command.options[:requires_gem])

gems_to_install.each do |g|
next if Rubygem.installed?(g)
output.puts "Installing `#{g}` gem..."

begin
Gem::DependencyInstaller.new.install(g)
rescue Gem::GemNotFoundException
raise CommandError, "Required Gem: `#{g}` not found. Aborting command installation."
end
output.puts "Installing #{ text.green(g) } gem..."
Rubygem.install(g)
end

Gem.refresh
gems_to_install.each do |g|
begin
require g
rescue LoadError
raise CommandError, "Required Gem: `#{g}` installed but not found?!. Aborting command installation."
fail_msg = "Required gem #{ text.green(g) } installed but not found."
fail_msg += " Aborting command installation\n"
fail_msg += 'Tips: 1. Check your PATH; 2. Run `bundle update`'
raise CommandError, fail_msg
end
end

output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
output.puts "Installation of #{ text.green(name) } successful! Type `help #{name}` for information"
end
end

Expand Down
14 changes: 11 additions & 3 deletions lib/pry/rubygem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ def complete(so_far)
# @param [String] name
# @return [void]
def install(name)
destination = File.writable?(Gem.dir) ? Gem.dir : Gem.user_dir
gemrc_opts = Gem.configuration['gem'].split(' ')
destination = if gemrc_opts.include?('--user-install')
Gem.user_dir
elsif File.writable?(Gem.dir)
Gem.dir
else
Gem.user_dir
end
installer = Gem::DependencyInstaller.new(:install_dir => destination)
installer.install(name)
rescue Errno::EACCES
raise CommandError,
"Insufficient permissions to install `#{ text.green(name) }`."
"Insufficient permissions to install #{ text.green(name) }."
rescue Gem::GemNotFoundException
raise CommandError, "Gem `#{ text.green(name) }` not found."
raise CommandError,
"Gem #{ text.green(name) } not found. Aborting installation."
else
Gem.refresh
end
Expand Down

0 comments on commit 074fe0e

Please sign in to comment.