Class | Gem::ConfigFile |
In: |
lib/rubygems/config_file.rb
|
Parent: | Object |
Store the gem command options specified in the configuration file. The config file object acts much like a hash.
DEFAULT_BACKTRACE | = | false |
DEFAULT_BENCHMARK | = | false |
DEFAULT_BULK_THRESHOLD | = | 1000 |
DEFAULT_VERBOSITY | = | true |
DEFAULT_UPDATE_SOURCES | = | true |
args | [R] | List of arguments supplied to the config file object. |
backtrace | [W] | True if we print backtraces on errors. |
benchmark | [RW] | True if we are benchmarking this run. |
bulk_threshold | [RW] | Bulk threshold value. If the number of missing gems are above this threshold value, then a bulk download technique is used. |
hash | [R] | |
update_sources | [RW] | True if we want to update the SourceInfoCache every time, false otherwise |
verbose | [RW] |
Verbose level of output:
|
Create the config file object. args is the list of arguments from the command line.
The following command line options are handled early here rather than later at the time most command options are processed.
# File lib/rubygems/config_file.rb, line 59 59: def initialize(arg_list) 60: @config_file_name = nil 61: need_config_file_name = false 62: 63: arg_list = arg_list.map do |arg| 64: if need_config_file_name then 65: @config_file_name = arg 66: nil 67: elsif arg =~ /^--config-file=(.*)/ then 68: @config_file_name = $1 69: nil 70: elsif arg =~ /^--config-file$/ then 71: need_config_file_name = true 72: nil 73: else 74: arg 75: end 76: end.compact 77: 78: @backtrace = DEFAULT_BACKTRACE 79: @benchmark = DEFAULT_BENCHMARK 80: @bulk_threshold = DEFAULT_BULK_THRESHOLD 81: @verbose = DEFAULT_VERBOSITY 82: @update_sources = DEFAULT_UPDATE_SOURCES 83: 84: begin 85: # HACK $SAFE ok? 86: @hash = open(config_file_name.dup.untaint) {|f| YAML.load(f) } 87: rescue ArgumentError 88: warn "Failed to load #{config_file_name}" 89: rescue Errno::ENOENT 90: # Ignore missing config file error. 91: rescue Errno::EACCES 92: warn "Failed to load #{config_file_name} due to permissions problem." 93: end 94: 95: @hash ||= {} 96: 97: # HACK these override command-line args, which is bad 98: @backtrace = @hash[:backtrace] if @hash.key? :backtrace 99: @benchmark = @hash[:benchmark] if @hash.key? :benchmark 100: @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold 101: Gem.sources.replace @hash[:sources] if @hash.key? :sources 102: @verbose = @hash[:verbose] if @hash.key? :verbose 103: @update_sources = @hash[:update_sources] if @hash.key? :update_sources 104: 105: handle_arguments arg_list 106: end
Return the configuration information for key.
# File lib/rubygems/config_file.rb, line 200 200: def [](key) 201: @hash[key.to_s] 202: end
Set configuration option key to value.
# File lib/rubygems/config_file.rb, line 205 205: def []=(key, value) 206: @hash[key.to_s] = value 207: end
The name of the configuration file.
# File lib/rubygems/config_file.rb, line 114 114: def config_file_name 115: @config_file_name || Gem.config_file 116: end
Delegates to @hash
# File lib/rubygems/config_file.rb, line 119 119: def each(&block) 120: hash = @hash.dup 121: hash.delete :update_sources 122: hash.delete :verbose 123: hash.delete :benchmark 124: hash.delete :backtrace 125: hash.delete :bulk_threshold 126: 127: yield :update_sources, @update_sources 128: yield :verbose, @verbose 129: yield :benchmark, @benchmark 130: yield :backtrace, @backtrace 131: yield :bulk_threshold, @bulk_threshold 132: 133: yield 'config_file_name', @config_file_name if @config_file_name 134: 135: hash.each(&block) 136: end
Handle the command arguments.
# File lib/rubygems/config_file.rb, line 139 139: def handle_arguments(arg_list) 140: @args = [] 141: 142: arg_list.each do |arg| 143: case arg 144: when /^--(backtrace|traceback)$/ then 145: @backtrace = true 146: when /^--bench(mark)?$/ then 147: @benchmark = true 148: when /^--debug$/ then 149: $DEBUG = true 150: else 151: @args << arg 152: end 153: end 154: end