class Gem::SourceList - Documentation for Ruby 4.0
Description: class Gem::SourceList: The SourceList represents the sources rubygems has been configured to use. SourceList.
Keywords: ruby,class,Gem::SourceList

🔍

No recent searches

# 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

sources [R]

The sources in this list

### Public Class Methods

from (ary)
Source

    # File lib/rubygems/source_list.rb, line 34
    def self.from(ary)
      list = new

      list.replace ary

      list
    end

Creates a new `SourceList` from an array of sources.

new ()
Source

    # File lib/rubygems/source_list.rb, line 22
    def initialize
      @sources = []
    end

Creates a new `SourceList`

### Public Instance Methods

<< (obj)
Source

    # 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

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

append (obj)
Source

    # File lib/rubygems/source_list.rb, line 85
    def append(obj)
      src = case obj
            when Gem::Source
              obj
            else
              Gem::Source.new(obj)
      end

      @sources.delete(src) if @sources.include?(src)
      @sources << src
      src
    end

Appends `obj` to the end of the source list, moving it if already present. `obj` may be a `Gem::Source`, `Gem::URI` or `URI` `String`. Moves `obj` to the end of the list if already present.

clear ()
Source

    # File lib/rubygems/source_list.rb, line 115
    def clear
      @sources.clear
    end

Removes all sources from the `SourceList`.

delete (source)
Source

    # File lib/rubygems/source_list.rb, line 175
    def delete(source)
      if source.is_a? Gem::Source
        @sources.delete source
      else
        @sources.delete_if {|x| x.uri.to_s == source.to_s }
      end
    end

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

each () { |uri.to_s| ... }
Source

    # File lib/rubygems/source_list.rb, line 122
    def each
      @sources.each {|s| yield s.uri.to_s }
    end

Yields each source `URI` in the list.

each_source (&b)
Source

    # File lib/rubygems/source_list.rb, line 129
    def each_source(&b)
      @sources.each(&b)
    end

Yields each source in the list.

empty? ()
Source

    # File lib/rubygems/source_list.rb, line 136
    def empty?
      @sources.empty?
    end

Returns true if there are no sources in this `SourceList`.

first ()
Source

    # File lib/rubygems/source_list.rb, line 156
    def first
      @sources.first
    end

Returns the first source in the list.

include? (other)
Source

    # File lib/rubygems/source_list.rb, line 164
    def include?(other)
      if other.is_a? Gem::Source
        @sources.include? other
      else
        @sources.find {|x| x.uri.to_s == other.to_s }
      end
    end

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

prepend (obj)
Source

    # File lib/rubygems/source_list.rb, line 67
    def prepend(obj)
      src = case obj
            when Gem::Source
              obj
            else
              Gem::Source.new(obj)
      end

      @sources.delete(src) if @sources.include?(src)
      @sources.unshift(src)
      src
    end

Prepends `obj` to the beginning of the source list which may be a `Gem::Source`, `Gem::URI` or `URI` Moves `obj` to the beginning of the list if already present. `String`.

replace (other)
Source

    # File lib/rubygems/source_list.rb, line 102
    def replace(other)
      clear

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

      self
    end

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

to_a ()
Source

    # File lib/rubygems/source_list.rb, line 147
    def to_a
      @sources.map {|x| x.uri.to_s }
    end

Returns an `Array` of source `URI` Strings.

Also aliased as: to_ary
to_ary ()
Alias for: to_a