diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 06:52:18 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 06:52:18 +0000 |
commit | 9694bb8cac12969300692dac5a1cf7aa4e3a46cd () | |
tree | c3cb423d701f7049ba9382de052e2a937cd1302d /lib/rubygems/config_file.rb | |
parent | 3f606b7063fc7a8b191556365ad343a314719a8d (diff) |
* lib/rubygems*: Updated to RubyGems 2.0
* test/rubygems*: ditto. * common.mk (prelude): Updated for RubyGems 2.0 source rearrangement. * tool/change_maker.rb: Allow invalid UTF-8 characters in source files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/rubygems/config_file.rb | 136 |
1 files changed, 82 insertions, 54 deletions
@@ -5,9 +5,9 @@ #++ ## -# Gem::ConfigFile RubyGems options and gem command options from ~/.gemrc. # -# ~/.gemrc is a YAML file that uses strings to match gem command arguments and # symbols to match RubyGems options. # # Gem command arguments use a String key that matches the command name and @@ -21,16 +21,19 @@ # RubyGems options use symbol keys. Valid options are: # # +:backtrace+:: See #backtrace -# +:benchmark+:: See #benchmark # +:sources+:: Sets Gem::sources # +:verbose+:: See #verbose - -require 'rbconfig' class Gem::ConfigFile DEFAULT_BACKTRACE = false - DEFAULT_BENCHMARK = false DEFAULT_BULK_THRESHOLD = 1000 DEFAULT_VERBOSITY = true DEFAULT_UPDATE_SOURCES = true @@ -97,11 +100,6 @@ class Gem::ConfigFile attr_writer :backtrace ## - # True if we are benchmarking this run. - - attr_accessor :benchmark - - ## # Bulk threshold value. If the number of missing gems are above this # threshold value, then a bulk download technique is used. (deprecated) @@ -131,6 +129,10 @@ class Gem::ConfigFile attr_reader :api_keys ## # openssl verify mode value, used for remote https connection attr_reader :ssl_verify_mode @@ -158,29 +160,29 @@ class Gem::ConfigFile # <tt>--debug</tt>:: # Enable Ruby level debug messages. Handled early for the same reason as # --backtrace. - def initialize(arg_list) @config_file_name = nil need_config_file_name = false - arg_list = arg_list.map do |arg| if need_config_file_name then @config_file_name = arg need_config_file_name = false - nil elsif arg =~ /^--config-file=(.*)/ then @config_file_name = $1 - nil elsif arg =~ /^--config-file$/ then need_config_file_name = true - nil else - arg end - end.compact @backtrace = DEFAULT_BACKTRACE - @benchmark = DEFAULT_BENCHMARK @bulk_threshold = DEFAULT_BULK_THRESHOLD @verbose = DEFAULT_VERBOSITY @update_sources = DEFAULT_UPDATE_SOURCES @@ -189,19 +191,25 @@ class Gem::ConfigFile platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS) system_config = load_file SYSTEM_WIDE_CONFIG_FILE user_config = load_file config_file_name.dup.untaint @hash = operating_system_config.merge platform_config @hash = @hash.merge system_config @hash = @hash.merge user_config # HACK these override command-line args, which is bad - @backtrace = @hash[:backtrace] if @hash.key? :backtrace - @benchmark = @hash[:benchmark] if @hash.key? :benchmark - @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold - @home = @hash[:gemhome] if @hash.key? :gemhome - @path = @hash[:gempath] if @hash.key? :gempath - @update_sources = @hash[:update_sources] if @hash.key? :update_sources - @verbose = @hash[:verbose] if @hash.key? :verbose @ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode @ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert @@ -224,6 +232,7 @@ class Gem::ConfigFile else @hash end if @api_keys.key? :rubygems_api_key then @rubygems_api_key = @api_keys[:rubygems_api_key] @api_keys[:rubygems] = @api_keys.delete :rubygems_api_key unless @api_keys.key? :rubygems @@ -238,7 +247,8 @@ class Gem::ConfigFile Gem.load_yaml - File.open(credentials_path, 'w') do |f| f.write config.to_yaml end @@ -249,13 +259,21 @@ class Gem::ConfigFile Gem.load_yaml return {} unless filename and File.exist? filename begin - YAML.load(File.read(filename)) rescue ArgumentError warn "Failed to load #{config_file_name}" rescue Errno::EACCES warn "Failed to load #{config_file_name} due to permissions problem." - end or {} end # True if the backtrace option has been specified, or debug is on. @@ -273,13 +291,11 @@ class Gem::ConfigFile hash = @hash.dup hash.delete :update_sources hash.delete :verbose - hash.delete :benchmark hash.delete :backtrace hash.delete :bulk_threshold yield :update_sources, @update_sources yield :verbose, @verbose - yield :benchmark, @benchmark yield :backtrace, @backtrace yield :bulk_threshold, @bulk_threshold @@ -296,8 +312,6 @@ class Gem::ConfigFile case arg when /^--(backtrace|traceback)$/ then @backtrace = true - when /^--bench(mark)?$/ then - @benchmark = true when /^--debug$/ then $DEBUG = true else @@ -309,25 +323,41 @@ class Gem::ConfigFile # Really verbose mode gives you extra output. def really_verbose case verbose - when true, false, nil then false - else true end end # to_yaml only overwrites things you can't override on the command line. def to_yaml # :nodoc: yaml_hash = {} - yaml_hash[:backtrace] = @hash.key?(:backtrace) ? @hash[:backtrace] : - DEFAULT_BACKTRACE - yaml_hash[:benchmark] = @hash.key?(:benchmark) ? @hash[:benchmark] : - DEFAULT_BENCHMARK - yaml_hash[:bulk_threshold] = @hash.key?(:bulk_threshold) ? - @hash[:bulk_threshold] : DEFAULT_BULK_THRESHOLD - yaml_hash[:sources] = Gem.sources - yaml_hash[:update_sources] = @hash.key?(:update_sources) ? - @hash[:update_sources] : DEFAULT_UPDATE_SOURCES - yaml_hash[:verbose] = @hash.key?(:verbose) ? @hash[:verbose] : - DEFAULT_VERBOSITY keys = yaml_hash.keys.map { |key| key.to_s } keys << 'debug' @@ -361,15 +391,13 @@ class Gem::ConfigFile def ==(other) # :nodoc: self.class === other and - @backtrace == other.backtrace and - @benchmark == other.benchmark and - @bulk_threshold == other.bulk_threshold and - @verbose == other.verbose and - @update_sources == other.update_sources and - @hash == other.hash end - protected - attr_reader :hash end |