Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Gem::ConfigFile constants for packagers and implementors to overr…

…ide.

git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1822 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
commit 9d9b59861b401925f0b68896b809d42bcd7ff968 1 parent df3bb81
drbrain authored
View
5 ChangeLog
@@ -1,4 +1,9 @@
# -*- coding: utf-8 -*-
+2008-06-25 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rubygems/config_file.rb: Add Gem::ConfigFile constants for
+ packagers and implementors to override defaults.
+
2008-06-24 Eric Hodel <drbrain@segment7.net>
* lib/rubygems/remote_fetcher.rb: Cleanup to support
View
22 lib/rubygems/config_file.rb
@@ -18,6 +18,18 @@ class Gem::ConfigFile
DEFAULT_VERBOSITY = true
DEFAULT_UPDATE_SOURCES = true
+ ##
+ # For Ruby packagers to set configuration defaults. Set in
+ # rubygems/defaults/operating_system.rb
+
+ OPERATING_SYSTEM_DEFAULTS = {}
+
+ ##
+ # For Ruby implementers to set configuration defaults. Set in
+ # rubygems/defaults/#{RUBY_ENGINE}.rb
+
+ PLATFORM_DEFAULTS = {}
+
system_config_path =
begin
require 'Win32API'
@@ -98,8 +110,14 @@ def initialize(arg_list)
@verbose = DEFAULT_VERBOSITY
@update_sources = DEFAULT_UPDATE_SOURCES
- @hash = load_file(SYSTEM_WIDE_CONFIG_FILE)
- @hash.merge!(load_file(config_file_name.dup.untaint))
+ operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS)
+ platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS)
+ system_config = load_file SYSTEM_WIDE_CONFIG_FILE
+ user_config = load_file config_file_name.dup.untaint
+
+ @hash = operating_system_config.merge platform_config
+ @hash = @hash.merge system_config
+ @hash = @hash.merge user_config
# HACK these override command-line args, which is bad
@backtrace = @hash[:backtrace] if @hash.key? :backtrace
View
63 test/test_gem_config_file.rb
@@ -22,11 +22,15 @@ def setup
Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
File.join(@tempdir, 'system-gemrc')
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
+ Gem::ConfigFile::PLATFORM_DEFAULTS.clear
util_config_file
end
def teardown
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
+ Gem::ConfigFile::PLATFORM_DEFAULTS.clear
Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
@orig_SYSTEM_WIDE_CONFIG_FILE
@@ -84,6 +88,48 @@ def test_initialize_handle_arguments_config_file_equals
assert_equal @temp_conf, @cfg.config_file_name
end
+ def test_initialize_operating_system_override
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS[:bulk_threshold] = 1
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS['install'] = '--no-env-shebang'
+
+ Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
+
+ util_config_file
+
+ assert_equal 2, @cfg.bulk_threshold
+ assert_equal '--no-env-shebang', @cfg[:install]
+ end
+
+ def test_initialize_platform_override
+ Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
+ Gem::ConfigFile::PLATFORM_DEFAULTS['install'] = '--no-env-shebang'
+
+ File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
+ fp.puts ":bulk_threshold: 3"
+ end
+
+ util_config_file
+
+ assert_equal 3, @cfg.bulk_threshold
+ assert_equal '--no-env-shebang', @cfg[:install]
+ end
+
+ def test_initialize_system_wide_override
+ File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
+ fp.puts ":backtrace: false"
+ fp.puts ":bulk_threshold: 2048"
+ end
+
+ File.open @temp_conf, 'w' do |fp|
+ fp.puts ":backtrace: true"
+ end
+
+ util_config_file
+
+ assert_equal 2048, @cfg.bulk_threshold
+ assert_equal true, @cfg.backtrace
+ end
+
def test_handle_arguments
args = %w[--backtrace --bunch --of --args here]
@@ -222,23 +268,6 @@ def test_write_from_hash
assert_equal %w[http://even-more-gems.example.com], Gem.sources
end
- def test_global_config_file
- File.open(@temp_conf, 'w') do |fp|
- fp.puts ":backtrace: true"
- end
-
- File.open(File.join(Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE),
- 'w') do |fp|
- fp.puts ":backtrace: false"
- fp.puts ":bulk_threshold: 2048"
- end
-
- util_config_file
-
- assert_equal 2048, @cfg.bulk_threshold
- assert @cfg.backtrace
- end
-
def util_config_file(args = @cfg_args)
@cfg = Gem::ConfigFile.new args
end
Please sign in to comment.
Something went wrong with that request. Please try again.