Class: Gem::Commands::YankCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems-source-cli/commands/yank_command.rb

Constant Summary collapse

RUBYGEMS_HOST =
"rubygems.org"

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ YankCommand

Returns a new instance of YankCommand.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubygems-source-cli/commands/yank_command.rb', line 4

def initialize(*args)
  super 'yank', description
  add_version_option("remove")
  add_platform_option("remove")
  add_option('--undo') do |value, options|
    options[:undo] = true
  end
  add_key_option
  add_option(
             '--host HOST',
             'Yank from another gemcutter-compatible host'
             ) do |value, options|
    options[:host] = value
  end
end

Instance Method Details

#executeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubygems-source-cli/commands/yank_command.rb', line 20

def execute
  sign_into_rubygems if host_is_rubygems? && !Gem.configuration.rubygems_api_key
  version   = get_version_from_requirements(options[:version])
  platform  = get_platform_from_requirements(options)
  
  if !version.nil?
    if options[:undo]
      unyank_gem(version, platform)
    else
      yank_gem(version, platform)
    end
  else
    say "A version argument is required: #{usage}"
    terminate_interaction
  end
end

#sign_into_rubygemsObject



47
48
49
# File 'lib/rubygems-source-cli/commands/yank_command.rb', line 47

def sign_into_rubygems
  
end

#unyank_gem(version, platform) ⇒ Object



42
43
44
45
# File 'lib/rubygems-source-cli/commands/yank_command.rb', line 42

def unyank_gem(version, platform)
  say "Unyanking gem from #{options[:host] || 'Rubygems.org'}..."
  yank_api_request(:put, version, platform, "api/v1/gems/unyank")
end

#yank_gem(version, platform) ⇒ Object



37
38
39
40
# File 'lib/rubygems-source-cli/commands/yank_command.rb', line 37

def yank_gem(version, platform)
  say "Yanking gem from #{options[:host] || 'Rubygems.org'}..."
  yank_api_request(:delete, version, platform, "api/v1/gems/yank")
end