Skip to content

Commit afac52f

Browse files
homusegiddins
authored andcommitted
Auto merge of #1699 - rubygems:bugfix/gem_sources_load_gemrc, r=bronzdoc
Load config in Gem.sources # Description: When calling `Gem.sources` load sources from configuration if present, else use default sources. closes #1613 # Tasks: - [x] Describe the problem / feature - [x] Write tests - [x] Write code to solve the problem - [ ] Get code review from coworkers / friends - [ ] [Squash commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
1 parent 81f4c77 commit afac52f

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

lib/rubygems.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,8 @@ def self.rubygems_version
971971
# default_sources if the sources list is empty.
972972

973973
def self.sources
974-
@sources ||= Gem::SourceList.from(default_sources)
974+
source_list = configuration.sources || default_sources
975+
@sources ||= Gem::SourceList.from(source_list)
975976
end
976977

977978
##

lib/rubygems/config_file.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class Gem::ConfigFile
143143

144144
attr_accessor :ssl_ca_cert
145145

146+
##
147+
# sources to look for gems
148+
attr_accessor :sources
149+
146150
##
147151
# Path name of directory or file of openssl client certificate, used for remote https connection with client authentication
148152

@@ -216,6 +220,7 @@ def initialize(args)
216220
@update_sources = @hash[:update_sources] if @hash.key? :update_sources
217221
@verbose = @hash[:verbose] if @hash.key? :verbose
218222
@disable_default_gem_server = @hash[:disable_default_gem_server] if @hash.key? :disable_default_gem_server
223+
@sources = @hash[:sources] if @hash.key? :sources
219224

220225
@ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
221226
@ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
@@ -224,7 +229,6 @@ def initialize(args)
224229
@api_keys = nil
225230
@rubygems_api_key = nil
226231

227-
Gem.sources = @hash[:sources] if @hash.key? :sources
228232
handle_arguments arg_list
229233
end
230234

test/rubygems/test_gem.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,9 @@ def test_self_pre_uninstall
961961

962962
def test_self_sources
963963
assert_equal %w[http://gems.example.com/], Gem.sources
964+
Gem.sources = nil
965+
Gem.configuration.sources = %w[http://test.example.com/]
966+
assert_equal %w[http://test.example.com/], Gem.sources
964967
end
965968

966969
def test_try_activate_returns_true_for_activated_specs

test/rubygems/test_gem_config_file.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ def test_initialize
6161
end
6262

6363
util_config_file
64-
6564
assert_equal true, @cfg.backtrace
6665
assert_equal 10, @cfg.bulk_threshold
6766
assert_equal false, @cfg.verbose
6867
assert_equal false, @cfg.update_sources
69-
assert_equal %w[http://more-gems.example.com], Gem.sources
68+
assert_equal %w[http://more-gems.example.com], @cfg.sources
7069
assert_equal '--wrappers', @cfg[:install]
7170
assert_equal(['/usr/ruby/1.8/lib/ruby/gems/1.8', '/var/ruby/1.8/gem_home'],
7271
@cfg.path)

0 commit comments

Comments
 (0)