Class: Gem::Commands::SboxCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::SboxCommand
- Defined in:
- lib/rubygems/commands/sbox_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
- #handle_response(response) ⇒ Object
-
#initialize ⇒ SboxCommand
constructor
A new instance of SboxCommand.
- #proxy ⇒ Object
- #send_gem ⇒ Object
- #setup ⇒ Object
- #strangebox_host ⇒ Object
- #strangebox_host=(host) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ SboxCommand
Returns a new instance of SboxCommand.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubygems/commands/sbox_command.rb', line 19 def initialize super 'sbox', description add_option('-c', '--configure', "Configure StrangeBox") 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
11 12 13 |
# File 'lib/rubygems/commands/sbox_command.rb', line 11 def arguments "GEM ... built gem to push up" end |
#config_path ⇒ Object
91 92 93 |
# File 'lib/rubygems/commands/sbox_command.rb', line 91 def config_path File.join(Gem.user_home, '.gem', 'strangebox') end |
#configure ⇒ Object
95 96 97 98 99 |
# File 'lib/rubygems/commands/sbox_command.rb', line 95 def configure say "StrangeBox:: Enter the root url for your personal strangebox instance. (E.g. http://gems/)" host = ask("Host:") self.strangebox_host = host end |
#description ⇒ Object
5 6 7 8 9 |
# File 'lib/rubygems/commands/sbox_command.rb', line 5 def description 'Push a gem up to your StrangeBox: $ gem build secretgem.gemspec ... build your Gem $ gem sbox ./secretgem-0.0.1.gem ... push Gem to StrangeBox' end |
#execute ⇒ Object
31 32 33 34 35 |
# File 'lib/rubygems/commands/sbox_command.rb', line 31 def execute return configure if [:configure] setup send_gem end |
#find_gem ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/rubygems/commands/sbox_command.rb', line 46 def find_gem say "StrangeBox:: 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 |
#handle_response(response) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/rubygems/commands/sbox_command.rb', line 82 def handle_response(response) case response when Net::HTTPSuccess, Net::HTTPRedirection puts response.body else response.error! end end |
#proxy ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/rubygems/commands/sbox_command.rb', line 74 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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rubygems/commands/sbox_command.rb', line 55 def send_gem # sanitize printed URL if a password is present url = URI.parse(strangebox_host) url_for_presentation = url.clone url_for_presentation.password = '***' if url_for_presentation.password say "StrangeBox:: 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
37 38 39 40 41 42 43 44 |
# File 'lib/rubygems/commands/sbox_command.rb', line 37 def setup @gemfile = if [:args].size == 0 find_gem else get_one_gem_name end configure unless strangebox_host end |
#strangebox_host ⇒ Object
101 102 103 |
# File 'lib/rubygems/commands/sbox_command.rb', line 101 def strangebox_host @strangebox_host ||= [:host] || Gem.configuration.load_file(config_path)[:host] end |
#strangebox_host=(host) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rubygems/commands/sbox_command.rb', line 105 def strangebox_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 |
#usage ⇒ Object
15 16 17 |
# File 'lib/rubygems/commands/sbox_command.rb', line 15 def usage "#{program_name} GEM" end |