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 | ||
OPERATING_SYSTEM_DEFAULTS | = | {} | For Ruby packagers to set configuration defaults. Set in rubygems/defaults/operating_system.rb | |
PLATFORM_DEFAULTS | = | {} | For Ruby implementers to set configuration defaults. Set in rubygems/defaults/#{RUBY_ENGINE}.rb | |
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] | |
home | [RW] | |
path | [RW] | Where to look for gems |
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 91 91: def initialize(arg_list) 92: @config_file_name = nil 93: need_config_file_name = false 94: 95: arg_list = arg_list.map do |arg| 96: if need_config_file_name then 97: @config_file_name = arg 98: need_config_file_name = false 99: nil 100: elsif arg =~ /^--config-file=(.*)/ then 101: @config_file_name = $1 102: nil 103: elsif arg =~ /^--config-file$/ then 104: need_config_file_name = true 105: nil 106: else 107: arg 108: end 109: end.compact 110: 111: @backtrace = DEFAULT_BACKTRACE 112: @benchmark = DEFAULT_BENCHMARK 113: @bulk_threshold = DEFAULT_BULK_THRESHOLD 114: @verbose = DEFAULT_VERBOSITY 115: @update_sources = DEFAULT_UPDATE_SOURCES 116: 117: operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS) 118: platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS) 119: system_config = load_file SYSTEM_WIDE_CONFIG_FILE 120: user_config = load_file config_file_name.dup.untaint 121: 122: @hash = operating_system_config.merge platform_config 123: @hash = @hash.merge system_config 124: @hash = @hash.merge user_config 125: 126: # HACK these override command-line args, which is bad 127: @backtrace = @hash[:backtrace] if @hash.key? :backtrace 128: @benchmark = @hash[:benchmark] if @hash.key? :benchmark 129: @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold 130: Gem.sources = @hash[:sources] if @hash.key? :sources 131: @verbose = @hash[:verbose] if @hash.key? :verbose 132: @update_sources = @hash[:update_sources] if @hash.key? :update_sources 133: @path = @hash[:gempath] if @hash.key? :gempath 134: @home = @hash[:gemhome] if @hash.key? :gemhome 135: 136: handle_arguments arg_list 137: end
Return the configuration information for key.
# File lib/rubygems/config_file.rb, line 241 241: def [](key) 242: @hash[key.to_s] 243: end
Set configuration option key to value.
# File lib/rubygems/config_file.rb, line 246 246: def []=(key, value) 247: @hash[key.to_s] = value 248: end
The name of the configuration file.
# File lib/rubygems/config_file.rb, line 155 155: def config_file_name 156: @config_file_name || Gem.config_file 157: end
Delegates to @hash
# File lib/rubygems/config_file.rb, line 160 160: def each(&block) 161: hash = @hash.dup 162: hash.delete :update_sources 163: hash.delete :verbose 164: hash.delete :benchmark 165: hash.delete :backtrace 166: hash.delete :bulk_threshold 167: 168: yield :update_sources, @update_sources 169: yield :verbose, @verbose 170: yield :benchmark, @benchmark 171: yield :backtrace, @backtrace 172: yield :bulk_threshold, @bulk_threshold 173: 174: yield 'config_file_name', @config_file_name if @config_file_name 175: 176: hash.each(&block) 177: end
Handle the command arguments.
# File lib/rubygems/config_file.rb, line 180 180: def handle_arguments(arg_list) 181: @args = [] 182: 183: arg_list.each do |arg| 184: case arg 185: when /^--(backtrace|traceback)$/ then 186: @backtrace = true 187: when /^--bench(mark)?$/ then 188: @benchmark = true 189: when /^--debug$/ then 190: $DEBUG = true 191: else 192: @args << arg 193: end 194: end 195: end
# File lib/rubygems/config_file.rb, line 139 139: def load_file(filename) 140: begin 141: YAML.load(File.read(filename)) if filename and File.exist?(filename) 142: rescue ArgumentError 143: warn "Failed to load #{config_file_name}" 144: rescue Errno::EACCES 145: warn "Failed to load #{config_file_name} due to permissions problem." 146: end or {} 147: end