PageRenderTime 114ms CodeModel.GetById 105ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/commands/push_command.rb

http://github.com/agross/netopenspace
Ruby | 60 lines | 46 code | 14 blank | 0 comment | 2 complexity | c6f3bb7a81fb6d5b4296b8ea40e97c3d MD5 | raw file
 1require 'rubygems/command'
 2require 'rubygems/local_remote_options'
 3require 'rubygems/gemcutter_utilities'
 4
 5class Gem::Commands::PushCommand < Gem::Command
 6  include Gem::LocalRemoteOptions
 7  include Gem::GemcutterUtilities
 8
 9  def description # :nodoc:
10    'Push a gem up to RubyGems.org'
11  end
12
13  def arguments # :nodoc:
14    "GEM       built gem to push up"
15  end
16
17  def usage # :nodoc:
18    "#{program_name} GEM"
19  end
20
21  def initialize
22    super 'push', description
23    add_proxy_option
24    add_key_option
25
26    add_option(
27      '--host HOST',
28      'Push to another gemcutter-compatible host'
29    ) do |value, options|
30      options[:host] = value
31    end
32  end
33
34  def execute
35    sign_in
36    send_gem get_one_gem_name
37  end
38
39  def send_gem name
40    args = [:post, "api/v1/gems"]
41
42    args << options[:host] if options[:host]
43
44    if Gem.latest_rubygems_version < Gem::Version.new(Gem::VERSION) then
45      alert_error "Using beta/unreleased version of rubygems. Not pushing."
46      terminate_interaction 1
47    end
48
49    response = rubygems_api_request(*args) do |request|
50      request.body = Gem.read_binary name
51      request.add_field "Content-Length", request.body.size
52      request.add_field "Content-Type",   "application/octet-stream"
53      request.add_field "Authorization",  api_key
54    end
55
56    with_response response
57  end
58
59end
60