Class: Gem::Commands::NukeCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/nuke_command.rb

Instance Method Summary collapse

Constructor Details

#initializeNukeCommand

Returns a new instance of NukeCommand.



7
8
9
10
11
12
13
14
# File 'lib/rubygems/commands/nuke_command.rb', line 7

def initialize
  super 'nuke', description

  add_option('-v', '--vault gemname1,gemname2', Array,
             "Gems in vault that'll survive this command.") do |vault, options|
    options[:vault] = vault.reject(&:nil?).collect(&:strip)
  end
end

Instance Method Details

#descriptionObject

:nodoc:



16
17
18
# File 'lib/rubygems/commands/nuke_command.rb', line 16

def description # :nodoc:
  'Nukes gems.'
end

#executeObject

Raises:

  • (OptionParser::InvalidArgument)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubygems/commands/nuke_command.rb', line 20

def execute
  raise OptionParser::InvalidArgument, options[:args] unless options[:args].empty?

  options[:vault] ||= []

  specs_to_uninstall = Gem::Specification.reject { |spec| options[:vault].include?(spec.name) }

  specs_to_uninstall.each do |spec|
    begin
      Gem::Uninstaller.new(spec.name, {
          force: true,
          executables: true
      }).uninstall
    rescue StandardError
      # ignored
    end
  end
end