aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/source_list.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-10 17:51:40 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-10 17:51:40 +0000
commit4f6779bac7b4e294bc473782d60cbd071f0d0f8d (patch)
treed37b54da20f8c0adf2d98e810aacc8259b0602ff /lib/rubygems/source_list.rb
parent31d355aaa9436e2b24efd5e6501cabd876267c46 (diff)
downloadruby-4f6779bac7b4e294bc473782d60cbd071f0d0f8d.tar.gz
* lib/rubygems: Update to RubyGems master 4bdc4f2. Important changes
in this commit: RubyGems now chooses the test server port reliably. Patch by akr. Partial implementation of bundler's Gemfile format. Refactorings to improve the new resolver. Fixes bugs in the resolver. * test/rubygems: Tests for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/source_list.rb')
-rw-r--r--lib/rubygems/source_list.rb71
1 files changed, 60 insertions, 11 deletions
diff --git a/lib/rubygems/source_list.rb b/lib/rubygems/source_list.rb
index 7bd8ef0b78..e6da50c2e5 100644
--- a/lib/rubygems/source_list.rb
+++ b/lib/rubygems/source_list.rb
@@ -1,28 +1,40 @@
require 'rubygems/source'
class Gem::SourceList
+
+ include Enumerable
+
+ ##
+ # Creates a new SourceList
+
def initialize
@sources = []
end
+ ##
+ # The sources in this list
+
attr_reader :sources
+ ##
+ # Creates a new SourceList from an array of sources.
+
def self.from(ary)
list = new
- if ary
- ary.each do |x|
- list << x
- end
- end
+ list.replace ary
return list
end
- def initialize_copy(other)
+ def initialize_copy(other) # :nodoc:
@sources = @sources.dup
end
+ ##
+ # Appends +obj+ to the source list which may be a Gem::Source, URI or URI
+ # String.
+
def <<(obj)
src = case obj
when URI
@@ -37,8 +49,12 @@ class Gem::SourceList
src
end
+ ##
+ # Replaces this SourceList with the sources in +other+ See #<< for
+ # acceptable items in +other+.
+
def replace(other)
- @sources.clear
+ clear
other.each do |x|
self << x
@@ -47,28 +63,58 @@ class Gem::SourceList
self
end
+ ##
+ # Removes all sources from the SourceList.
+
+ def clear
+ @sources.clear
+ end
+
+ ##
+ # Yields each source URI in the list.
+
def each
@sources.each { |s| yield s.uri.to_s }
end
+ ##
+ # Yields each source in the list.
+
def each_source(&b)
@sources.each(&b)
end
+ ##
+ # Returns true if there are no sources in this SourceList.
+
+ def empty?
+ @sources.empty?
+ end
+
def ==(other)
to_a == other
end
+ ##
+ # Returns an Array of source URI Strings.
+
def to_a
@sources.map { |x| x.uri.to_s }
end
alias_method :to_ary, :to_a
+ ##
+ # Returns the first source in the list.
+
def first
@sources.first
end
+ ##
+ # Returns true if this source list includes +other+ which may be a
+ # Gem::Source or a source URI.
+
def include?(other)
if other.kind_of? Gem::Source
@sources.include? other
@@ -77,11 +123,14 @@ class Gem::SourceList
end
end
- def delete(uri)
- if uri.kind_of? Gem::Source
- @sources.delete uri
+ ##
+ # Deletes +source+ from the source list which may be a Gem::Source or a URI.
+
+ def delete source
+ if source.kind_of? Gem::Source
+ @sources.delete source
else
- @sources.delete_if { |x| x.uri.to_s == uri.to_s }
+ @sources.delete_if { |x| x.uri.to_s == source.to_s }
end
end
end