Class: Gem::Commands::BanCommand

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

Instance Method Summary collapse

Constructor Details

#initializeBanCommand

Returns a new instance of BanCommand.



4
5
6
# File 'lib/rubygems/commands/ban_command.rb', line 4

def initialize
  super 'ban', 'Specific gem installation prevention utility'
end

Instance Method Details

#addObject



43
44
45
46
47
48
# File 'lib/rubygems/commands/ban_command.rb', line 43

def add
  until (gem = options[:args].shift).nil?
    raise Gem::CommandLineError, "Please specify a gem name to ban on the command line" unless gem
    Gem::Ban::ban(gem)
  end
end

#argumentsObject

:nodoc:



8
9
10
11
# File 'lib/rubygems/commands/ban_command.rb', line 8

def arguments # :nodoc:
  ['SUBCOMMAND    list, add or remove',
   'GEMNAME(s)    name of a gem to ban or unban'].join "\n"
end

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubygems/commands/ban_command.rb', line 17

def execute
  cmd = options[:args].shift

  if %w|list add remove|.include? cmd
    return eval("#{cmd}")
  end

  if %w|help h usage --usage --help -h -?|.include? cmd 
    show_help
    abort
  end

  alert_error "Unknown ban subcommand: #{cmd}"
  show_help
  abort
end

#listObject



35
36
37
38
39
40
41
# File 'lib/rubygems/commands/ban_command.rb', line 35

def list
  unless (_banned = Gem::Ban::banned.join(' ')).empty?
    puts "Banned gems:  #{_banned}"
  else
    puts 'Banned gems: (none)'
  end
end

#removeObject



50
51
52
53
54
55
# File 'lib/rubygems/commands/ban_command.rb', line 50

def remove
  until (gem = options[:args].shift).nil?
    raise Gem::CommandLineError, "Please specify a gem name to unban on the command line" unless gem
    Gem::Ban::unban(gem)
  end
end

#usageObject

:nodoc:



13
14
15
# File 'lib/rubygems/commands/ban_command.rb', line 13

def usage # :nodoc:
  "#{program_name} SUBCOMMAND GEMNAME(S)"
end