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