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 allow you to specify default arguments:
install: --no-rdoc --no-ri update: --no-rdoc --no-ri
You can use gem: to set default arguments for all commands.
RubyGems options use symbol keys. Valid options are:
:backtrace | See # |
:benchmark | See # |
:sources | Sets Gem::sources |
:verbose | See # |
For Ruby packagers to set configuration defaults. Set in rubygems/defaults/operating_system.rb
For Ruby implementers to set configuration defaults. Set in rubygems/defaults/#{RUBY_ENGINE}.rb
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.
--config-file, --config-file==NAME | Obviously these need to be handled by the ConfigFile object to ensure we get the right config file. |
--backtrace | Backtrace needs to be turned on early so that errors before normal option parsing can be properly handled. |
--debug | Enable Ruby level debug messages. Handled early for the same reason as —backtrace. |
# File lib/rubygems/config_file.rb, line 126 126: def initialize(arg_list) 127: @config_file_name = nil 128: need_config_file_name = false 129: 130: arg_list = arg_list.map do |arg| 131: if need_config_file_name then 132: @config_file_name = arg 133: need_config_file_name = false 134: nil 135: elsif arg =~ /^--config-file=(.*)/ then 136: @config_file_name = $1 137: nil 138: elsif arg =~ /^--config-file$/ then 139: need_config_file_name = true 140: nil 141: else 142: arg 143: end 144: end.compact 145: 146: @backtrace = DEFAULT_BACKTRACE 147: @benchmark = DEFAULT_BENCHMARK 148: @bulk_threshold = DEFAULT_BULK_THRESHOLD 149: @verbose = DEFAULT_VERBOSITY 150: @update_sources = DEFAULT_UPDATE_SOURCES 151: 152: operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS) 153: platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS) 154: system_config = load_file SYSTEM_WIDE_CONFIG_FILE 155: user_config = load_file config_file_name.dup.untaint 156: 157: @hash = operating_system_config.merge platform_config 158: @hash = @hash.merge system_config 159: @hash = @hash.merge user_config 160: 161: # HACK these override command-line args, which is bad 162: @backtrace = @hash[:backtrace] if @hash.key? :backtrace 163: @benchmark = @hash[:benchmark] if @hash.key? :benchmark 164: @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold 165: @home = @hash[:gemhome] if @hash.key? :gemhome 166: @path = @hash[:gempath] if @hash.key? :gempath 167: @update_sources = @hash[:update_sources] if @hash.key? :update_sources 168: @verbose = @hash[:verbose] if @hash.key? :verbose 169: 170: load_rubygems_api_key 171: 172: Gem.sources = @hash[:sources] if @hash.key? :sources 173: handle_arguments arg_list 174: end
Return the configuration information for key.
# File lib/rubygems/config_file.rb, line 309 309: def [](key) 310: @hash[key.to_s] 311: end
Set configuration option key to value.
# File lib/rubygems/config_file.rb, line 314 314: def []=(key, value) 315: @hash[key.to_s] = value 316: end
True if the backtrace option has been specified, or debug is on.
# File lib/rubygems/config_file.rb, line 217 217: def backtrace 218: @backtrace or $DEBUG 219: end
The name of the configuration file.
# File lib/rubygems/config_file.rb, line 222 222: def config_file_name 223: @config_file_name || Gem.config_file 224: end
Location of RubyGems.org credentials
# File lib/rubygems/config_file.rb, line 179 179: def credentials_path 180: File.join(Gem.user_home, '.gem', 'credentials') 181: end
Delegates to @hash
# File lib/rubygems/config_file.rb, line 227 227: def each(&block) 228: hash = @hash.dup 229: hash.delete :update_sources 230: hash.delete :verbose 231: hash.delete :benchmark 232: hash.delete :backtrace 233: hash.delete :bulk_threshold 234: 235: yield :update_sources, @update_sources 236: yield :verbose, @verbose 237: yield :benchmark, @benchmark 238: yield :backtrace, @backtrace 239: yield :bulk_threshold, @bulk_threshold 240: 241: yield 'config_file_name', @config_file_name if @config_file_name 242: 243: hash.each(&block) 244: end
Handle the command arguments.
# File lib/rubygems/config_file.rb, line 247 247: def handle_arguments(arg_list) 248: @args = [] 249: 250: arg_list.each do |arg| 251: case arg 252: when /^--(backtrace|traceback)$/ then 253: @backtrace = true 254: when /^--bench(mark)?$/ then 255: @benchmark = true 256: when /^--debug$/ then 257: $DEBUG = true 258: else 259: @args << arg 260: end 261: end 262: end
# File lib/rubygems/config_file.rb, line 204 204: def load_file(filename) 205: return {} unless filename and File.exists?(filename) 206: begin 207: require 'yaml' 208: YAML.load(File.read(filename)) 209: rescue ArgumentError 210: warn "Failed to load #{config_file_name}" 211: rescue Errno::EACCES 212: warn "Failed to load #{config_file_name} due to permissions problem." 213: end or {} 214: end
# File lib/rubygems/config_file.rb, line 183 183: def load_rubygems_api_key 184: api_key_hash = File.exists?(credentials_path) ? load_file(credentials_path) : @hash 185: 186: @rubygems_api_key = api_key_hash[:rubygems_api_key] if api_key_hash.key? :rubygems_api_key 187: end
Really verbose mode gives you extra output.
# File lib/rubygems/config_file.rb, line 265 265: def really_verbose 266: case verbose 267: when true, false, nil then false 268: else true 269: end 270: end
# File lib/rubygems/config_file.rb, line 189 189: def rubygems_api_key=(api_key) 190: config = load_file(credentials_path).merge(:rubygems_api_key => api_key) 191: 192: dirname = File.dirname(credentials_path) 193: Dir.mkdir(dirname) unless File.exists?(dirname) 194: 195: require 'yaml' 196: 197: File.open(credentials_path, 'w') do |f| 198: f.write config.to_yaml 199: end 200: 201: @rubygems_api_key = api_key 202: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.