In Files

  • rubygems/source_list.rb

Class/Module Index [+]

Quicksearch

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.add '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) click to toggle source

Creates a new SourceList from an array of sources.

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

  list.replace ary

  return list
end
            
new() click to toggle source

Creates a new SourceList

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

Public Instance Methods

<<(obj) click to toggle source

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

 
               # File rubygems/source_list.rb, line 51
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
            
clear() click to toggle source

Removes all sources from the SourceList.

 
               # File rubygems/source_list.rb, line 82
def clear
  @sources.clear
end
            
delete(source) click to toggle source

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

 
               # File rubygems/source_list.rb, line 142
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() click to toggle source

Yields each source URI in the list.

 
               # File rubygems/source_list.rb, line 89
def each
  @sources.each { |s| yield s.uri.to_s }
end
            
each_source(&b) click to toggle source

Yields each source in the list.

 
               # File rubygems/source_list.rb, line 96
def each_source(&b)
  @sources.each(&b)
end
            
empty?() click to toggle source

Returns true if there are no sources in this SourceList.

 
               # File rubygems/source_list.rb, line 103
def empty?
  @sources.empty?
end
            
first() click to toggle source

Returns the first source in the list.

 
               # File rubygems/source_list.rb, line 123
def first
  @sources.first
end
            
include?(other) click to toggle source

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

 
               # File rubygems/source_list.rb, line 131
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
            
replace(other) click to toggle source

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

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

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

  self
end
            
to_a() click to toggle source

Returns an Array of source URI Strings.

 
               # File rubygems/source_list.rb, line 114
def to_a
  @sources.map { |x| x.uri.to_s }
end
            
Also aliased as: to_ary
to_ary() click to toggle source
Alias for: to_a

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus