diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 06:52:18 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 06:52:18 +0000 |
commit | 9694bb8cac12969300692dac5a1cf7aa4e3a46cd (patch) | |
tree | c3cb423d701f7049ba9382de052e2a937cd1302d /lib/rubygems/source_list.rb | |
parent | 3f606b7063fc7a8b191556365ad343a314719a8d (diff) | |
download | ruby-9694bb8cac12969300692dac5a1cf7aa4e3a46cd.tar.gz |
* lib/rubygems*: Updated to RubyGems 2.0
* test/rubygems*: ditto.
* common.mk (prelude): Updated for RubyGems 2.0 source rearrangement.
* tool/change_maker.rb: Allow invalid UTF-8 characters in source
files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/source_list.rb')
-rw-r--r-- | lib/rubygems/source_list.rb | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/rubygems/source_list.rb b/lib/rubygems/source_list.rb new file mode 100644 index 0000000000..7bd8ef0b78 --- /dev/null +++ b/lib/rubygems/source_list.rb @@ -0,0 +1,87 @@ +require 'rubygems/source' + +class Gem::SourceList + def initialize + @sources = [] + end + + attr_reader :sources + + def self.from(ary) + list = new + + if ary + ary.each do |x| + list << x + end + end + + return list + end + + def initialize_copy(other) + @sources = @sources.dup + end + + def <<(obj) + src = case obj + when URI + Gem::Source.new(obj) + when Gem::Source + obj + else + Gem::Source.new(URI.parse(obj)) + end + + @sources << src + src + end + + def replace(other) + @sources.clear + + other.each do |x| + self << x + end + + self + end + + def each + @sources.each { |s| yield s.uri.to_s } + end + + def each_source(&b) + @sources.each(&b) + end + + def ==(other) + to_a == other + end + + def to_a + @sources.map { |x| x.uri.to_s } + end + + alias_method :to_ary, :to_a + + def first + @sources.first + end + + def include?(other) + if other.kind_of? Gem::Source + @sources.include? other + else + @sources.find { |x| x.uri.to_s == other.to_s } + end + end + + def delete(uri) + if uri.kind_of? Gem::Source + @sources.delete uri + else + @sources.delete_if { |x| x.uri.to_s == uri.to_s } + end + end +end |