class Gem::SourceList
The SourceList
represents the sources rubygems has been configured to use. A source may be created from an array of sources:
Gem::SourceList.from %w[https://rubygems.example https://internal.example]
Or by adding them:
sources = Gem::SourceList.new sources << 'https://rubygems.example'
The most common way to get a SourceList
is Gem.sources
.
Attributes
The sources in this list
Public Class Methods
Creates a new SourceList
from an array of sources.
# File lib/rubygems/source_list.rb, line 36 def self.from(ary) list = new list.replace ary return list end
Creates a new SourceList
# File lib/rubygems/source_list.rb, line 24 def initialize @sources = [] end
Public Instance Methods
Appends obj
to the source list which may be a Gem::Source
, URI
or URI
String.
# File lib/rubygems/source_list.rb, line 52 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 unless @sources.include?(src) src end
Removes all sources from the SourceList
.
# File lib/rubygems/source_list.rb, line 83 def clear @sources.clear end
Deletes source
from the source list which may be a Gem::Source
or a URI
.
# File lib/rubygems/source_list.rb, line 143 def delete source if source.kind_of? Gem::Source @sources.delete source else @sources.delete_if { |x| x.uri.to_s == source.to_s } end end
Yields each source URI
in the list.
# File lib/rubygems/source_list.rb, line 90 def each @sources.each { |s| yield s.uri.to_s } end
Yields each source in the list.
# File lib/rubygems/source_list.rb, line 97 def each_source(&b) @sources.each(&b) end
Returns true if there are no sources in this SourceList
.
# File lib/rubygems/source_list.rb, line 104 def empty? @sources.empty? end
Returns the first source in the list.
# File lib/rubygems/source_list.rb, line 124 def first @sources.first end
Returns true if this source list includes other
which may be a Gem::Source
or a source URI
.
# File lib/rubygems/source_list.rb, line 132 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
Replaces this SourceList
with the sources in other
See <<
for acceptable items in other
.
# File lib/rubygems/source_list.rb, line 70 def replace(other) clear other.each do |x| self << x end self end