class Gem::SourceList
SourceList
表示 rubygems 配置要使用的源。可以从源数组创建源
Gem::SourceList.from %w[https://rubygems.example https://internal.example]
或者通过添加它们
sources = Gem::SourceList.new sources << 'https://rubygems.example'
获取 SourceList
的最常见方法是 Gem.sources
。
属性
此列表中的源
公共类方法
源
# File lib/rubygems/source_list.rb, line 34 def self.from(ary) list = new list.replace ary list end
从源数组创建一个新的 SourceList
。
源
# File lib/rubygems/source_list.rb, line 22 def initialize @sources = [] end
创建一个新的 SourceList
公共实例方法
源
# 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
追加到源列表,它可以是 Gem::Source
、Gem::URI
或 URI
String
。
源
# File lib/rubygems/source_list.rb, line 79 def clear @sources.clear end
从 SourceList
中删除所有源。
源
# File lib/rubygems/source_list.rb, line 139 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
,它可以是 Gem::Source
或 URI
。
源
# File lib/rubygems/source_list.rb, line 86 def each @sources.each {|s| yield s.uri.to_s } end
遍历列表中的每个源 URI
。
源
# File lib/rubygems/source_list.rb, line 93 def each_source(&b) @sources.each(&b) end
遍历列表中的每个源。
源
# File lib/rubygems/source_list.rb, line 100 def empty? @sources.empty? end
如果此 SourceList
中没有源,则返回 true。
源
# File lib/rubygems/source_list.rb, line 128 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,它可以是 Gem::Source
或源 URI
。
源
# File lib/rubygems/source_list.rb, line 66 def replace(other) clear other.each do |x| self << x end self end
将此 SourceList
替换为 other
中的源。有关 other
中可接受的项,请参见 <<
。
源
# File lib/rubygems/source_list.rb, line 111 def to_a @sources.map {|x| x.uri.to_s } end
也别名为: to_ary