123456789_123456789_123456789_123456789_123456789_

Class: Gem::SourceList

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Enumerable
Inherits: Object
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 sources.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newSourceList

Creates a new SourceList

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 24

def initialize
  @sources = []
end

Class Method Details

.from(ary)

Creates a new SourceList from an array of sources.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 36

def self.from(ary)
  list = new

  list.replace ary

  return list
end

Instance Attribute Details

#empty?Boolean (readonly)

Returns true if there are no sources in this SourceList.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 106

def empty?
  @sources.empty?
end

#sources (readonly)

The sources in this list

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 31

attr_reader :sources

Instance Method Details

#<<(obj)

Appends obj to the source list which may be a Source, URI or URI String.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 52

def <<(obj)
  require "uri"

  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

#==(other)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 110

def ==(other) # :nodoc:
  to_a == other
end

#clear

Removes all sources from the SourceList.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 85

def clear
  @sources.clear
end

#delete(source)

Deletes source from the source list which may be a Source or a URI.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 145

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

Yields each source URI in the list.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 92

def each
  @sources.each { |s| yield s.uri.to_s }
end

#each_source(&b)

Yields each source in the list.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 99

def each_source(&b)
  @sources.each(&b)
end

#first

Returns the first source in the list.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 126

def first
  @sources.first
end

#include?(other) ⇒ Boolean

Returns true if this source list includes other which may be a Source or a source URI.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 134

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)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 44

def initialize_copy(other) # :nodoc:
  @sources = @sources.dup
end

#replace(other)

Replaces this SourceList with the sources in other See #<< for acceptable items in other.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 72

def replace(other)
  clear

  other.each do |x|
    self << x
  end

  self
end

#to_a Also known as: #to_ary

Returns an Array of source URI Strings.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 117

def to_a
  @sources.map { |x| x.uri.to_s }
end

#to_ary

Alias for #to_a.

[ GitHub ]

  
# File 'lib/rubygems/source_list.rb', line 121

alias_method :to_ary, :to_a