123456789_123456789_123456789_123456789_123456789_

Class: Gem::Resolver::APISpecification

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Gem::Resolver::Specification
Defined in: lib/rubygems/resolver/api_specification.rb

Overview

Represents a specification retrieved via the Compact Index API.

This is used to avoid loading the full Specification object when all we need is the name, version, and dependencies.

Class Method Summary

Specification - Inherited

.new

Sets default instance variables for the specification.

Instance Attribute Summary

Specification - Inherited

#dependencies

The dependencies of the gem for this specification.

#installable_platform?

Returns true if this specification is installable on this platform.

#name

The name of the gem for this specification.

#platform

The platform this gem works on.

#required_ruby_version

The required_ruby_version constraint for this specification.

#required_rubygems_version

The required_ruby_version constraint for this specification.

#set

The set this specification came from.

#source

The source for this specification.

#spec
#version

The version of the gem for this specification.

#local?

Instance Method Summary

Specification - Inherited

#download,
#full_name

The name and version of the specification.

#install

Installs this specification using the ::Gem::Installer options.

#fetch_development_dependencies

Fetches development dependencies if the source does not provide them by default (see APISpecification).

Constructor Details

.new(set, api_data) ⇒ APISpecification

[ GitHub ]

  
# File 'lib/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

#initialize(set, api_data) ⇒ APISpecification

Creates an APISpecification for the given set from the Compact Index API api_data.

See guides.rubygems.org/rubygems-org-compact-index-api for the format of the api_data.

[ GitHub ]

  
# File 'lib/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

Instance Attribute Details

#installable_platform?Boolean (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/api_specification.rb', line 61

def installable_platform? # :nodoc:
  Gem::Platform.match_gem? @platform, @name
end

Instance Method Details

#==(other)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/api_specification.rb', line 43

def ==(other) # :nodoc:
  self.class === other &&
    @set          == other.set &&
    @name         == other.name &&
    @version      == other.version &&
    @platform     == other.platform
end

#fetch_development_dependencies

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/api_specification.rb', line 55

def fetch_development_dependencies # :nodoc:
  spec = source.fetch_spec Gem::NameTuple.new @name, @version, @platform

  @dependencies = spec.dependencies
end

#hash

[ GitHub ]

  
# File 'lib/rubygems/resolver/api_specification.rb', line 51

def hash
  @set.hash ^ @name.hash ^ @version.hash ^ @platform.hash
end

#pretty_print(q)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/api_specification.rb', line 65

def pretty_print(q) # :nodoc:
  q.group 2, "[APISpecification", "]" do
    q.breakable
    q.text "name: #{name}"

    q.breakable
    q.text "version: #{version}"

    q.breakable
    q.text "platform: #{platform}"

    q.breakable
    q.text "dependencies:"
    q.breakable
    q.pp @dependencies

    q.breakable
    q.text "set uri: #{@set.dep_uri}"
  end
end

#source

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/api_specification.rb', line 102

def source # :nodoc:
  @set.source
end

#spec

This method is for internal use only.

Fetches a ::Gem::Specification for this APISpecification.

[ GitHub ]

  
# File 'lib/rubygems/resolver/api_specification.rb', line 89

def spec # :nodoc:
  @spec ||=
    begin
      tuple = Gem::NameTuple.new @name, @version, @platform
      source.fetch_spec tuple
    rescue Gem::RemoteFetcher::FetchError
      raise if @original_platform == @platform

      tuple = Gem::NameTuple.new @name, @version, @original_platform
      source.fetch_spec tuple
    end
end