class Gem::SourceList
The SourceList 表示 rubygems 配置使用的源。源可以从源数组创建
Gem::SourceList.from %w[https://rubygems.example https://internal.example]
或者通过添加它们
sources = Gem::SourceList.new sources << 'https://rubygems.example'
获取 SourceList 最常见的方法是 Gem.sources。
属性
此列表中的源
Public Class Methods
Source
# File lib/rubygems/source_list.rb, line 34 def self.from(ary) list = new list.replace ary list end
从源数组创建新的 SourceList。
Public Instance Methods
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
将 obj 追加到源列表,obj 可以是 Gem::Source、Gem::URI 或 URI String。
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
将 obj 追加到源列表的末尾,如果已存在则移动它。obj 可以是 Gem::Source、Gem::URI 或 URI String。如果 obj 已存在,则将其移动到列表末尾。
Source
# File lib/rubygems/source_list.rb, line 115 def clear @sources.clear end
从 SourceList 中删除所有源。
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
从源列表中删除 source,source 可以是 Gem::Source 或 URI。
Source
# File lib/rubygems/source_list.rb, line 122 def each @sources.each {|s| yield s.uri.to_s } end
遍历列表中的每个源 URI。
Source
# File lib/rubygems/source_list.rb, line 129 def each_source(&b) @sources.each(&b) end
遍历列表中的每个源。
Source
# File lib/rubygems/source_list.rb, line 136 def empty? @sources.empty? end
如果此 SourceList 中没有源,则返回 true。
Source
# File lib/rubygems/source_list.rb, line 156 def first @sources.first end
返回列表中的第一个源。
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
如果此源列表包含 other,则返回 true,other 可以是 Gem::Source 或源 URI。
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
将 obj 添加到源列表的开头,obj 可以是 Gem::Source、Gem::URI 或 URI。如果 obj 已存在,则将其移动到列表开头。 String。
Source
# File lib/rubygems/source_list.rb, line 102 def replace(other) clear other.each do |x| self << x end self end
用 other 中的源替换此 SourceList。请参阅 << 以了解 other 中可接受的项。
Source
# File lib/rubygems/source_list.rb, line 147 def to_a @sources.map {|x| x.uri.to_s } end
也别名为: to_ary