Class: EmptyCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/gem-empty/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEmptyCommand

Returns a new instance of EmptyCommand.



10
11
12
13
# File 'lib/gem-empty/command.rb', line 10

def initialize
  super 'empty', 'Remove all gems from current GEM_HOME.'
  @default_options = { :install_dir => Gem.dir, :force => true, :executables => true }
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/gem-empty/command.rb', line 8

def options
  @options
end

Instance Method Details

#argumentsObject

:nodoc:



15
16
17
# File 'lib/gem-empty/command.rb', line 15

def arguments # :nodoc:
  "empty        remove all gems from current GEM_HOME."
end

#defaults_strObject

:nodoc:



23
24
25
# File 'lib/gem-empty/command.rb', line 23

def defaults_str # :nodoc:
  ""
end

#descriptionObject

:nodoc:



27
28
29
30
31
# File 'lib/gem-empty/command.rb', line 27

def description # :nodoc:
  <<-DOC
Remove all gems from current 'GEM_HOME'.
DOC
end

#execute(opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gem-empty/command.rb', line 33

def execute(opts = {})
  @options = @default_options.merge(opts)
  uninstaller = Gem::Uninstaller.new(nil, options)
  uninstaller.remove_all(gem_dir_specs)

  # Remove any Git gems installed via bundler
  FileUtils.rm_rf( File.join( options[:install_dir] ,'bundler','gems' ) )

rescue Gem::DependencyRemovalException,
       Gem::InstallError,
       Gem::GemNotInHomeException,
       Gem::FilePermissionError => e

  alert_error "#{e.class}: #{e.message}"
end

#usageObject

:nodoc:



19
20
21
# File 'lib/gem-empty/command.rb', line 19

def usage # :nodoc:
  "#{program_name}"
end