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 |
CSIDL_COMMON_APPDATA | = | 0x0023 |
SHGetFolderPath | = | Win32API.new 'shell32', 'SHGetFolderPath', 'LLLLP', 'L' |
SYSTEM_WIDE_CONFIG_FILE | = | File.join system_config_path, 'gemrc' |
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 75 75: def initialize(arg_list) 76: @config_file_name = nil 77: need_config_file_name = false 78: 79: arg_list = arg_list.map do |arg| 80: if need_config_file_name then 81: @config_file_name = arg 82: need_config_file_name = false 83: nil 84: elsif arg =~ /^--config-file=(.*)/ then 85: @config_file_name = $1 86: nil 87: elsif arg =~ /^--config-file$/ then 88: need_config_file_name = true 89: nil 90: else 91: arg 92: end 93: end.compact 94: 95: @backtrace = DEFAULT_BACKTRACE 96: @benchmark = DEFAULT_BENCHMARK 97: @bulk_threshold = DEFAULT_BULK_THRESHOLD 98: @verbose = DEFAULT_VERBOSITY 99: @update_sources = DEFAULT_UPDATE_SOURCES 100: 101: @hash = load_file(SYSTEM_WIDE_CONFIG_FILE) 102: @hash.merge!(load_file(config_file_name.dup.untaint)) 103: 104: # HACK these override command-line args, which is bad 105: @backtrace = @hash[:backtrace] if @hash.key? :backtrace 106: @benchmark = @hash[:benchmark] if @hash.key? :benchmark 107: @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold 108: Gem.sources.replace @hash[:sources] if @hash.key? :sources 109: @verbose = @hash[:verbose] if @hash.key? :verbose 110: @update_sources = @hash[:update_sources] if @hash.key? :update_sources 111: 112: handle_arguments arg_list 113: end
Return the configuration information for key.
# File lib/rubygems/config_file.rb, line 217 217: def [](key) 218: @hash[key.to_s] 219: end
Set configuration option key to value.
# File lib/rubygems/config_file.rb, line 222 222: def []=(key, value) 223: @hash[key.to_s] = value 224: end
The name of the configuration file.
# File lib/rubygems/config_file.rb, line 131 131: def config_file_name 132: @config_file_name || Gem.config_file 133: end
Delegates to @hash
# File lib/rubygems/config_file.rb, line 136 136: def each(&block) 137: hash = @hash.dup 138: hash.delete :update_sources 139: hash.delete :verbose 140: hash.delete :benchmark 141: hash.delete :backtrace 142: hash.delete :bulk_threshold 143: 144: yield :update_sources, @update_sources 145: yield :verbose, @verbose 146: yield :benchmark, @benchmark 147: yield :backtrace, @backtrace 148: yield :bulk_threshold, @bulk_threshold 149: 150: yield 'config_file_name', @config_file_name if @config_file_name 151: 152: hash.each(&block) 153: end
Handle the command arguments.
# File lib/rubygems/config_file.rb, line 156 156: def handle_arguments(arg_list) 157: @args = [] 158: 159: arg_list.each do |arg| 160: case arg 161: when /^--(backtrace|traceback)$/ then 162: @backtrace = true 163: when /^--bench(mark)?$/ then 164: @benchmark = true 165: when /^--debug$/ then 166: $DEBUG = true 167: else 168: @args << arg 169: end 170: end 171: end
# File lib/rubygems/config_file.rb, line 115 115: def load_file(filename) 116: begin 117: YAML.load(File.read(filename)) if filename and File.exist?(filename) 118: rescue ArgumentError 119: warn "Failed to load #{config_file_name}" 120: rescue Errno::EACCES 121: warn "Failed to load #{config_file_name} due to permissions problem." 122: end or {} 123: end