Class: Gem::Commands::InaboxCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::InaboxCommand
- Defined in:
- lib/rubygems/commands/inabox_command.rb
Defined Under Namespace
Modules: Multipart
Instance Method Summary collapse
- #arguments ⇒ Object
- #config_path ⇒ Object
- #configure ⇒ Object
- #description ⇒ Object
- #execute ⇒ Object
- #find_gem ⇒ Object
- #geminabox_host ⇒ Object
- #geminabox_host=(host) ⇒ Object
- #handle_response(response) ⇒ Object
-
#initialize ⇒ InaboxCommand
constructor
A new instance of InaboxCommand.
- #proxy ⇒ Object
- #send_gem ⇒ Object
- #setup ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ InaboxCommand
Returns a new instance of InaboxCommand.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubygems/commands/inabox_command.rb', line 17 def initialize super 'inabox', description add_option('-c', '--configure', "Configure GemInABox") do |value, | [:configure] = true end add_option('-g', '--host HOST', "Host to upload to.") do |value, | [:host] = value end end |
Instance Method Details
#arguments ⇒ Object
9 10 11 |
# File 'lib/rubygems/commands/inabox_command.rb', line 9 def arguments "GEM built gem to push up" end |
#config_path ⇒ Object
89 90 91 |
# File 'lib/rubygems/commands/inabox_command.rb', line 89 def config_path File.join(Gem.user_home, '.gem', 'geminabox') end |
#configure ⇒ Object
93 94 95 96 97 |
# File 'lib/rubygems/commands/inabox_command.rb', line 93 def configure say "Enter the root url for your personal geminabox instance. (E.g. http://gems/)" host = ask("Host:") self.geminabox_host = host end |
#description ⇒ Object
5 6 7 |
# File 'lib/rubygems/commands/inabox_command.rb', line 5 def description 'Push a gem up to your GemInABox' end |
#execute ⇒ Object
29 30 31 32 33 |
# File 'lib/rubygems/commands/inabox_command.rb', line 29 def execute return configure if [:configure] setup send_gem end |
#find_gem ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/rubygems/commands/inabox_command.rb', line 44 def find_gem say "You didn't specify a gem, looking for one in pkg..." path, directory = File.split(Dir.pwd) possible_gems = Dir.glob("pkg/#{directory}-*.gem") raise Gem::CommandLineError, "Couldn't find a gem in pkg, please specify a gem name on the command line (e.g. gem inabox GEMNAME)" unless possible_gems.any? name_regexp = Regexp.new("^pkg/#{directory}-") possible_gems.sort_by{ |a| Gem::Version.new(a.sub(name_regexp,'')) }.last end |
#geminabox_host ⇒ Object
99 100 101 |
# File 'lib/rubygems/commands/inabox_command.rb', line 99 def geminabox_host @geminabox_host ||= [:host] || Gem.configuration.load_file(config_path)[:host] end |
#geminabox_host=(host) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rubygems/commands/inabox_command.rb', line 103 def geminabox_host=(host) config = Gem.configuration.load_file(config_path).merge(:host => host) dirname = File.dirname(config_path) Dir.mkdir(dirname) unless File.exists?(dirname) File.open(config_path, 'w') do |f| f.write config.to_yaml end end |
#handle_response(response) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/rubygems/commands/inabox_command.rb', line 80 def handle_response(response) case response when Net::HTTPSuccess, Net::HTTPRedirection puts response.body else response.error! end end |
#proxy ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/rubygems/commands/inabox_command.rb', line 72 def proxy if proxy_info = ENV['http_proxy'] || ENV['HTTP_PROXY'] and uri = URI.parse(proxy_info) Net::HTTP::Proxy(uri.host, uri.port, uri.user, uri.password) else Net::HTTP end end |
#send_gem ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rubygems/commands/inabox_command.rb', line 53 def send_gem # sanitize printed URL if a password is present url = URI.parse(geminabox_host) url_for_presentation = url.clone url_for_presentation.password = '***' if url_for_presentation.password say "Pushing #{File.split(@gemfile).last} to #{url_for_presentation}..." File.open(@gemfile, "rb") do |file| request_body, request_headers = Multipart::MultipartPost.new.prepare_query("file" => file) proxy.start(url.host, url.port) {|con| req = Net::HTTP::Post.new('/upload', request_headers) req.basic_auth(url.user, url.password) if url.user handle_response(con.request(req, request_body)) } end end |
#setup ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/rubygems/commands/inabox_command.rb', line 35 def setup @gemfile = if [:args].size == 0 find_gem else get_one_gem_name end configure unless geminabox_host end |
#usage ⇒ Object
13 14 15 |
# File 'lib/rubygems/commands/inabox_command.rb', line 13 def usage "#{program_name} GEM" end |