Class: Gem::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/config_file.rb

Overview

Store the gem command options specified in the configuration file. The config file object acts much like a hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg_list) ⇒ ConfigFile

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 and –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.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubygems/config_file.rb', line 46

def initialize(arg_list)
  @config_file_name = nil
  @verbose = true
  handle_arguments(arg_list)
  begin
    @hash = open(config_file_name) {|f| YAML.load(f) }
  rescue ArgumentError
    warn "Failed to load #{config_file_name}"
  rescue Errno::ENOENT
    # Ignore missing config file error.
  rescue Errno::EACCES                 
    warn "Failed to load #{config_file_name} due to permissions problem."
  end
  @hash ||= {}
end

Instance Attribute Details

#argsObject (readonly)

List of arguments supplied to the config file object.



22
23
24
# File 'lib/rubygems/config_file.rb', line 22

def args
  @args
end

#backtraceObject (readonly)

True if the backtrace option has been specified.



19
20
21
# File 'lib/rubygems/config_file.rb', line 19

def backtrace
  @backtrace
end

#verboseObject

Verbose level of output:

  • false – No output

  • true – Normal output

  • :loud – Extra output



28
29
30
# File 'lib/rubygems/config_file.rb', line 28

def verbose
  @verbose
end

Instance Method Details

#[](key) ⇒ Object

Return the configuration information for key.



68
69
70
# File 'lib/rubygems/config_file.rb', line 68

def [](key)
  @hash[key.to_s]
end

#config_file_nameObject

The name of the configuration file.



63
64
65
# File 'lib/rubygems/config_file.rb', line 63

def config_file_name
  @config_file_name || Gem.config_file
end