Class: Gem::Commands::OwnerCommand

Inherits:
Gem::Command show all
Includes:
GemcutterUtilities, LocalRemoteOptions
Defined in:
lib/rubygems/commands/owner_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 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

#initializeOwnerCommand

Returns a new instance of OwnerCommand.



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

def initialize
  super 'owner', description
  add_proxy_option
  add_key_option
  defaults.merge! :add => [], :remove => []

  add_option '-a', '--add EMAIL', 'Add an owner' do |value, options|
    options[:add] << value
  end

  add_option '-r', '--remove EMAIL', 'Remove an owner' do |value, options|
    options[:remove] << value
  end
end

Instance Method Details

#add_owners(name, owners) ⇒ Object



60
61
62
# File 'lib/rubygems/commands/owner_command.rb', line 60

def add_owners name, owners
  manage_owners :post, name, owners
end

#argumentsObject

:nodoc:



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

def arguments # :nodoc:
  "GEM       gem to manage owners for"
end

#descriptionObject

:nodoc:



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

def description # :nodoc:
  'Manage gem owners on RubyGems.org.'
end

#executeObject



36
37
38
39
40
41
42
43
# File 'lib/rubygems/commands/owner_command.rb', line 36

def execute
  
  name = get_one_gem_name

  add_owners    name, options[:add]
  remove_owners name, options[:remove]
  show_owners   name
end

#manage_owners(method, name, owners) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rubygems/commands/owner_command.rb', line 68

def manage_owners method, name, owners
  owners.each do |owner|
    begin
      response = rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request|
        request.set_form_data 'email' => owner
        request.add_field "Authorization", api_key
      end

      with_response response
    rescue
      # ignore
    end
  end
end

#remove_owners(name, owners) ⇒ Object



64
65
66
# File 'lib/rubygems/commands/owner_command.rb', line 64

def remove_owners name, owners
  manage_owners :delete, name, owners
end

#show_owners(name) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rubygems/commands/owner_command.rb', line 45

def show_owners name
  response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request|
    request.add_field "Authorization", api_key
  end

  with_response response do |resp|
    owners = YAML.load resp.body

    say "Owners for gem: #{name}"
    owners.each do |owner|
      say "- #{owner['email']}"
    end
  end
end

#usageObject

:nodoc:



17
18
19
# File 'lib/rubygems/commands/owner_command.rb', line 17

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