Class: Gem::Commands::YankCommand

Inherits:
Gem::Command show all
Includes:
GemcutterUtilities, LocalRemoteOptions, VersionOption
Defined in:
lib/rubygems/commands/yank_command.rb

Instance Attribute Summary

Attributes included from GemcutterUtilities

#host

Attributes inherited from Gem::Command

#command, #defaults, #options, #program_name, #summary

Instance Method Summary collapse

Methods included from GemcutterUtilities

#add_key_option, #api_key, #rubygems_api_request, #sign_in, #verify_api_key, #with_response

Methods included from VersionOption

#add_platform_option, #add_prerelease_option, #add_version_option

Methods included from LocalRemoteOptions

#accept_uri_http, #add_bulk_threshold_option, #add_clear_sources_option, #add_local_remote_options, #add_proxy_option, #add_source_option, #add_update_sources_option, #both?, #local?, #remote?

Methods inherited from Gem::Command

add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, common_options, #defaults_str, extra_args, extra_args=, #get_all_gem_names, #get_all_gem_names_and_versions, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #invoke_with_build_args, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked

Methods included from UserInteraction

#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction

Methods included from DefaultUserInteraction

ui, #ui, ui=, #ui=, use_ui, #use_ui

Constructor Details

#initializeYankCommand

Returns a new instance of YankCommand.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rubygems/commands/yank_command.rb', line 37

def initialize
  super 'yank', 'Remove a pushed gem from the index'

  add_version_option("remove")
  add_platform_option("remove")

  add_option('--undo') do |value, options|
    options[:undo] = true
  end

  add_option('-k', '--key KEY_NAME',
             'Use API key from your gem credentials file') do |value, options|
    options[:key] = value
  end
end

Instance Method Details

#argumentsObject

:nodoc:



29
30
31
# File 'lib/rubygems/commands/yank_command.rb', line 29

def arguments # :nodoc:
  "GEM       name of gem"
end

#descriptionObject

:nodoc:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubygems/commands/yank_command.rb', line 11

def description # :nodoc:
  <<-EOF
The yank command removes a gem you pushed to a server from the server's
index.

Note that if you push a gem to rubygems.org the yank command does not
prevent other people from downloading the gem via the download link.

Once you have pushed a gem several downloads will happen automatically
via the webhooks.  If you accidentally pushed passwords or other sensitive
data you will need to change them immediately and yank your gem.

If you are yanking a gem due to intellectual property reasons contact
http://help.rubygems.org for permanant removal.  Be sure to mention this
as the reason for the removal request.
  EOF
end

#executeObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rubygems/commands/yank_command.rb', line 53

def execute
  

  version   = get_version_from_requirements(options[:version])
  platform  = get_platform_from_requirements(options)
  api_key   = Gem.configuration.rubygems_api_key
  api_key   = Gem.configuration.api_keys[options[:key].to_sym] if options[:key]

  if version then
    if options[:undo] then
      unyank_gem(version, platform, api_key)
    else
      yank_gem(version, platform, api_key)
    end
  else
    say "A version argument is required: #{usage}"
    terminate_interaction
  end
end

#unyank_gem(version, platform, api_key) ⇒ Object



78
79
80
81
# File 'lib/rubygems/commands/yank_command.rb', line 78

def unyank_gem(version, platform, api_key)
  say "Unyanking gem from #{host}..."
  yank_api_request(:put, version, platform, "api/v1/gems/unyank", api_key)
end

#usageObject

:nodoc:



33
34
35
# File 'lib/rubygems/commands/yank_command.rb', line 33

def usage # :nodoc:
  "#{program_name} GEM -v VERSION [-p PLATFORM] [--undo] [--key KEY_NAME]"
end

#yank_gem(version, platform, api_key) ⇒ Object



73
74
75
76
# File 'lib/rubygems/commands/yank_command.rb', line 73

def yank_gem(version, platform, api_key)
  say "Yanking gem from #{self.host}..."
  yank_api_request(:delete, version, platform, "api/v1/gems/yank", api_key)
end