/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

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