aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/gemcutter_utilities.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-13 19:58:57 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-13 19:58:57 +0000
commit1daa0b113d853bfa57b776cc569939b61ca14292 (patch)
treef8c4acb08a551820299dff2b13966d6ac38d31e4 /lib/rubygems/gemcutter_utilities.rb
parent85995e88d49c442b5b113c2676456133e79f5c02 (diff)
downloadruby-1daa0b113d853bfa57b776cc569939b61ca14292.tar.gz
* lib/rubygems: Update to RubyGems 2.1.3
Fixed installing platform gems Restored concurrent requires Fixed installing gems with extensions with --install-dir Fixed `gem fetch -v` to install the latest version Fixed installing gems with "./" in their files entries * test/rubygems/test_gem_package.rb: Tests for the above. * NEWS: Updated for RubyGems 2.1.3 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/gemcutter_utilities.rb')
-rw-r--r--lib/rubygems/gemcutter_utilities.rb114
1 files changed, 41 insertions, 73 deletions
diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb
index 9dbc18ba98..04d7cd300f 100644
--- a/lib/rubygems/gemcutter_utilities.rb
+++ b/lib/rubygems/gemcutter_utilities.rb
@@ -1,17 +1,11 @@
require 'rubygems/remote_fetcher'
-##
-# Utility methods for using the RubyGems API.
-
module Gem::GemcutterUtilities
-
# TODO: move to Gem::Command
OptionParser.accept Symbol do |value|
value.to_sym
end
- attr_writer :host
-
##
# Add the --key option
@@ -23,9 +17,6 @@ module Gem::GemcutterUtilities
end
end
- ##
- # The API key from the command options or from the user's configuration.
-
def api_key
if options[:key] then
verify_api_key options[:key]
@@ -36,49 +27,7 @@ module Gem::GemcutterUtilities
end
end
- ##
- # The host to connect to either from the RUBYGEMS_HOST environment variable
- # or from the user's configuration
-
- def host
- configured_host = Gem.host unless
- Gem.configuration.disable_default_gem_server
-
- @host ||=
- begin
- env_rubygems_host = ENV['RUBYGEMS_HOST']
- env_rubygems_host = nil if
- env_rubygems_host and env_rubygems_host.empty?
-
- env_rubygems_host|| configured_host
- end
- end
-
- ##
- # Creates an RubyGems API to +host+ and +path+ with the given HTTP +method+.
-
- def rubygems_api_request(method, path, host = nil, &block)
- require 'net/http'
-
- self.host = host if host
- unless self.host
- alert_error "You must specify a gem server"
- terminate_interaction 1 # TODO: question this
- end
-
- uri = URI.parse "#{self.host}/#{path}"
-
- request_method = Net::HTTP.const_get method.to_s.capitalize
-
- Gem::RemoteFetcher.fetcher.request(uri, request_method, &block)
- end
-
- ##
- # Signs in with the RubyGems API at +sign_in_host+ and sets the rubygems API
- # key.
-
- def sign_in sign_in_host = nil
- sign_in_host ||= self.host
+ def sign_in sign_in_host = self.host
return if Gem.configuration.rubygems_api_key
pretty_host = if Gem::DEFAULT_HOST == sign_in_host then
@@ -106,36 +55,47 @@ module Gem::GemcutterUtilities
end
end
- ##
- # Retrieves the pre-configured API key +key+ or terminates interaction with
- # an error.
+ attr_writer :host
+ def host
+ configured_host = Gem.host unless
+ Gem.configuration.disable_default_gem_server
- def verify_api_key(key)
- if Gem.configuration.api_keys.key? key then
- Gem.configuration.api_keys[key]
- else
- alert_error "No such API key. Please add it to your configuration (done automatically on initial `gem push`)."
+ @host ||=
+ begin
+ env_rubygems_host = ENV['RUBYGEMS_HOST']
+ env_rubygems_host = nil if
+ env_rubygems_host and env_rubygems_host.empty?
+
+ env_rubygems_host|| configured_host
+ end
+ end
+
+ def rubygems_api_request(method, path, host = nil, &block)
+ require 'net/http'
+
+ self.host = host if host
+ unless self.host
+ alert_error "You must specify a gem server"
terminate_interaction 1 # TODO: question this
end
+
+ uri = URI.parse "#{self.host}/#{path}"
+
+ request_method = Net::HTTP.const_get method.to_s.capitalize
+
+ Gem::RemoteFetcher.fetcher.request(uri, request_method, &block)
end
- ##
- # If +response+ is an HTTP Success (2XX) response, yields the response if a
- # block was given or shows the response body to the user.
- #
- # If the response was not successful, shows an error to the user including
- # the +error_prefix+ and the response body.
-
- def with_response response, error_prefix = nil
- case response
+ def with_response resp, error_prefix = nil
+ case resp
when Net::HTTPSuccess then
if block_given? then
- yield response
+ yield resp
else
- say response.body
+ say resp.body
end
else
- message = response.body
+ message = resp.body
message = "#{error_prefix}: #{message}" if error_prefix
say message
@@ -143,5 +103,13 @@ module Gem::GemcutterUtilities
end
end
-end
+ def verify_api_key(key)
+ if Gem.configuration.api_keys.key? key then
+ Gem.configuration.api_keys[key]
+ else
+ alert_error "No such API key. Please add it to your configuration (done automatically on initial `gem push`)."
+ terminate_interaction 1 # TODO: question this
+ end
+ end
+end