Skip to content
Browse files

removing geminabox client code

  • Loading branch information...
1 parent 0e26fa6 commit 35f7cb25d7f482a60807bb15e76761650825c416 Subba Rao Pasupuleti committed Apr 16, 2012
Showing with 0 additions and 146 deletions.
  1. +0 −59 lib/geminabox_client.rb
  2. +0 −87 lib/rubygems/commands/inabox_command.rb
View
59 lib/geminabox_client.rb
@@ -1,59 +0,0 @@
-require 'uri'
-require 'httpclient'
-
-class GeminaboxClient
- attr_reader :url, :http_client
-
- def initialize(url)
- extract_username_and_password_from_url!(url)
- @http_client = HTTPClient.new
- @http_client.set_auth(url_for(:upload), @username, @password) if @username or @password
- @http_client.www_auth.basic_auth.challenge(url_for(:upload)) # Workaround: https://github.com/nahi/httpclient/issues/63
- @http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
- @http_client.send_timeout = 600
- end
-
- def extract_username_and_password_from_url!(url)
- uri = URI.parse(url.to_s)
- @username, @password = uri.user, uri.password
- uri.user = uri.password = nil
- uri.path = uri.path + "/" unless uri.path.end_with?("/")
- @url = uri.to_s
- end
-
- def url_for(path)
- url + path.to_s
- end
-
- def push(gemfile)
- response = http_client.post(url_for(:upload), {'file' => File.open(gemfile, "rb")}, {'Accept' => 'text/plain'})
-
- if response.status < 300
- response.body
- else
- raise GeminaboxClient::Error, "Error (#{response.code} received)\n\n#{response.body}"
- end
- end
-
-end
-
-class GeminaboxClient::Error < RuntimeError
-end
-
-module GeminaboxClient::GemLocator
- def find_gem(dir)
- gemname = File.split(dir).last
- glob_matcher = "{pkg/,}#{gemname}-*.gem"
- latest_gem_for(gemname, Dir.glob(glob_matcher)) or raise Gem::CommandLineError, NO_GEM_PROVIDED_ERROR_MESSAGE
- end
-
- def latest_gem_for(gemname, files)
- regexp_matcher = %r{(?:pkg/)#{gemname}-(#{Gem::Version::VERSION_PATTERN})\.gem}
- sorter = lambda{|v| Gem::Version.new(regexp_matcher.match(v)[1]) }
- files.grep(regexp_matcher).max_by(&sorter)
- end
-
- extend self
-
- NO_GEM_PROVIDED_ERROR_MESSAGE = "Couldn't find a gem in pkg, please specify a gem name on the command line (e.g. gem inabox GEMNAME)"
-end
View
87 lib/rubygems/commands/inabox_command.rb
@@ -1,87 +0,0 @@
-require 'rubygems/command'
-
-class Gem::Commands::InaboxCommand < Gem::Command
- def description
- 'Push a gem up to your GemInABox'
- end
-
- def arguments
- "GEM built gem to push up"
- end
-
- def usage
- "#{program_name} GEM"
- end
-
- def initialize
- super 'inabox', description
-
- add_option('-c', '--configure', "Configure GemInABox") do |value, options|
- options[:configure] = true
- end
-
- add_option('-g', '--host HOST', "Host to upload to.") do |value, options|
- options[:host] = value
- end
- end
-
- def last_minute_requires!
- require 'yaml'
- require File.expand_path("../../../geminabox_client.rb", __FILE__)
- end
-
- def execute
- last_minute_requires!
- return configure if options[:configure]
- configure unless geminabox_host
-
- if options[:args].size == 0
- say "You didn't specify a gem, looking for one in . and in ./pkg/..."
- gemfiles = [GeminaboxClient::GemLocator.find_gem(Dir.pwd)]
- else
- gemfiles = get_all_gem_names
- end
-
- send_gems(gemfiles)
- end
-
- def send_gems(gemfiles)
- client = GeminaboxClient.new(geminabox_host)
-
- gemfiles.each do |gemfile|
- say "Pushing #{File.basename(gemfile)} to #{client.url}..."
- begin
- say client.push(gemfile)
- rescue GeminaboxClient::Error => e
- alert_error e.message
- terminate_interaction(1)
- end
- end
- end
-
- def config_path
- File.join(Gem.user_home, '.gem', 'geminabox')
- end
-
- def configure
- say "Enter the root url for your personal geminabox instance. (E.g. http://gems/)"
- host = ask("Host:")
- self.geminabox_host = host
- end
-
- def geminabox_host
- @geminabox_host ||= options[:host] || Gem.configuration.load_file(config_path)[:host]
- end
-
- 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
-
-end

0 comments on commit 35f7cb2

Please sign in to comment.
Something went wrong with that request. Please try again.