类 Gem::Resolver::APISpecification

表示通过 rubygems.org API 检索到的规范。

这用于避免在只需要名称、版本和依赖项时加载完整的 Specification 对象。

公共类方法

new(set, api_data) 点击切换源代码
# File rubygems/resolver/api_specification.rb, line 14
def self.new(set, api_data)
  cache_key = [set, api_data]
  cache = @@cache[cache_key]
  return cache if cache
  @@cache[cache_key] = super
end
new(set, api_data) 点击切换源代码

从 rubygems.org 的 api_data 为给定的 set 创建一个 APISpecification

有关 api_data 的格式,请参阅 guides.rubygems.org/rubygems-org-api/#misc-methods

# File rubygems/resolver/api_specification.rb, line 28
def initialize(set, api_data)
  super()

  @set = set
  @name = api_data[:name]
  @version = Gem::Version.new(api_data[:number]).freeze
  @platform = Gem::Platform.new(api_data[:platform]).freeze
  @original_platform = api_data[:platform].freeze
  @dependencies = api_data[:dependencies].map do |name, ver|
    Gem::Dependency.new(name, ver.split(/\s*,\s*/)).freeze
  end.freeze
  @required_ruby_version = Gem::Requirement.new(api_data.dig(:requirements, :ruby)).freeze
  @required_rubygems_version = Gem::Requirement.new(api_data.dig(:requirements, :rubygems)).freeze
end

公共实例方法

hash() 点击切换源代码
# File rubygems/resolver/api_specification.rb, line 51
def hash
  @set.hash ^ @name.hash ^ @version.hash ^ @platform.hash
end