Class: Gem::SourceList
- Inherits:
 - 
      Object
      
        
- Object
 - Gem::SourceList
 
 
- Includes:
 - Enumerable
 
- Defined in:
 - lib/rubygems/source_list.rb
 
Overview
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.
Instance Attribute Summary collapse
- 
  
    
      #sources  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The sources in this list.
 
Class Method Summary collapse
- 
  
    
      .from(ary)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Creates a new SourceList from an array of sources.
 
Instance Method Summary collapse
- 
  
    
      #<<(obj)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Appends
objto the source list which may be a Gem::Source, URI or URI String. - 
  
    
      #==(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
:nodoc:.
 - 
  
    
      #clear  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Removes all sources from the SourceList.
 - 
  
    
      #delete(source)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Deletes
sourcefrom the source list which may be a Gem::Source or a URI. - 
  
    
      #each  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Yields each source URI in the list.
 - 
  
    
      #each_source(&b)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Yields each source in the list.
 - 
  
    
      #empty?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns true if there are no sources in this SourceList.
 - 
  
    
      #first  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the first source in the list.
 - 
  
    
      #include?(other)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns true if this source list includes
otherwhich may be a Gem::Source or a source URI. - 
  
    
      #initialize  ⇒ SourceList 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Creates a new SourceList.
 - 
  
    
      #initialize_copy(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
:nodoc:.
 - 
  
    
      #replace(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Replaces this SourceList with the sources in
otherSee #<< for acceptable items inother. - 
  
    
      #to_a  ⇒ Object 
    
    
      (also: #to_ary)
    
  
  
  
  
  
  
  
  
  
    
Returns an Array of source URI Strings.
 
Constructor Details
#initialize ⇒ SourceList
Creates a new SourceList
      22 23 24  | 
    
      # File 'lib/rubygems/source_list.rb', line 22 def initialize @sources = [] end  | 
  
Instance Attribute Details
#sources ⇒ Object (readonly)
The sources in this list
      29 30 31  | 
    
      # File 'lib/rubygems/source_list.rb', line 29 def sources @sources end  | 
  
Class Method Details
.from(ary) ⇒ Object
Creates a new SourceList from an array of sources.
      34 35 36 37 38 39 40  | 
    
      # File 'lib/rubygems/source_list.rb', line 34 def self.from(ary) list = new list.replace ary return list end  | 
  
Instance Method Details
#<<(obj) ⇒ Object
Appends obj to the source list which may be a Gem::Source, URI or URI String.
      50 51 52 53 54 55 56 57 58 59 60  | 
    
      # File 'lib/rubygems/source_list.rb', line 50 def <<(obj) src = case obj when Gem::Source obj else Gem::Source.new(obj) end @sources << src unless @sources.include?(src) src end  | 
  
#==(other) ⇒ Object
:nodoc:
      104 105 106  | 
    
      # File 'lib/rubygems/source_list.rb', line 104 def ==(other) # :nodoc: to_a == other end  | 
  
#clear ⇒ Object
Removes all sources from the SourceList.
      79 80 81  | 
    
      # File 'lib/rubygems/source_list.rb', line 79 def clear @sources.clear end  | 
  
#delete(source) ⇒ Object
Deletes source from the source list which may be a Gem::Source or a URI.
      139 140 141 142 143 144 145  | 
    
      # File 'lib/rubygems/source_list.rb', line 139 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  | 
  
#each ⇒ Object
Yields each source URI in the list.
      86 87 88  | 
    
      # File 'lib/rubygems/source_list.rb', line 86 def each @sources.each {|s| yield s.uri.to_s } end  | 
  
#each_source(&b) ⇒ Object
Yields each source in the list.
      93 94 95  | 
    
      # File 'lib/rubygems/source_list.rb', line 93 def each_source(&b) @sources.each(&b) end  | 
  
#empty? ⇒ Boolean
Returns true if there are no sources in this SourceList.
      100 101 102  | 
    
      # File 'lib/rubygems/source_list.rb', line 100 def empty? @sources.empty? end  | 
  
#first ⇒ Object
Returns the first source in the list.
      120 121 122  | 
    
      # File 'lib/rubygems/source_list.rb', line 120 def first @sources.first end  | 
  
#include?(other) ⇒ Boolean
Returns true if this source list includes other which may be a Gem::Source or a source URI.
      128 129 130 131 132 133 134  | 
    
      # File 'lib/rubygems/source_list.rb', line 128 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  | 
  
#initialize_copy(other) ⇒ Object
:nodoc:
      42 43 44  | 
    
      # File 'lib/rubygems/source_list.rb', line 42 def initialize_copy(other) # :nodoc: @sources = @sources.dup end  | 
  
#replace(other) ⇒ Object
Replaces this SourceList with the sources in other  See #<< for acceptable items in other.
      66 67 68 69 70 71 72 73 74  | 
    
      # File 'lib/rubygems/source_list.rb', line 66 def replace(other) clear other.each do |x| self << x end self end  | 
  
#to_a ⇒ Object Also known as: to_ary
Returns an Array of source URI Strings.
      111 112 113  | 
    
      # File 'lib/rubygems/source_list.rb', line 111 def to_a @sources.map {|x| x.uri.to_s } end  |