Class: Gem::Resolver::APISpecification
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Specification
|
|
|
Instance Chain:
self,
Specification
|
|
| 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
- .new(set, api_data) ⇒ APISpecification constructor
Specification - Inherited
| .new | Sets default instance variables for the specification. |
Instance Attribute Summary
- #installable_platform? ⇒ Boolean readonly Internal use only
Specification - Inherited
| #created_at | The time this gem version was published, when the source provides it (compact index v2), nil otherwise. |
| #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 | The |
| #version | The version of the gem for this specification. |
| #local? | |
Instance Method Summary
- #hash
-
#initialize(set, api_data) ⇒ APISpecification
constructor
Creates an
APISpecificationfor the givensetfrom the Compact Index APIapi_data. - #parse_created_at(value) private
- #==(other) Internal use only
- #fetch_development_dependencies Internal use only
- #pretty_print(q) Internal use only
- #source Internal use only
-
#spec
Internal use only
A
::Gem::Specificationstub built from the Compact Index data for this specification.
Specification - Inherited
| #download, | |
| #full_name | The name and version of the specification. |
| #install | Installs this specification using the |
| #fetch_development_dependencies | Fetches development dependencies if the source does not provide them by default (see |
Constructor Details
.new(set, api_data) ⇒ APISpecification
# 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 https://guides.rubygems.org/rubygems-org-compact-index-api for the
format of the api_data.
# 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 @created_at = parse_created_at(api_data.dig(:requirements, :created_at))&.freeze end
Instance Attribute Details
#installable_platform? ⇒ Boolean (readonly)
# File 'lib/rubygems/resolver/api_specification.rb', line 62
def installable_platform? # :nodoc: Gem::Platform.match_gem? @platform, @name end
Instance Method Details
#==(other)
# File 'lib/rubygems/resolver/api_specification.rb', line 44
def ==(other) # :nodoc: self.class === other && @set == other.set && @name == other.name && @version == other.version && @platform == other.platform end
#fetch_development_dependencies
#hash
[ GitHub ]# File 'lib/rubygems/resolver/api_specification.rb', line 52
def hash @set.hash ^ @name.hash ^ @version.hash ^ @platform.hash end
#parse_created_at(value) (private)
[ GitHub ]# File 'lib/rubygems/resolver/api_specification.rb', line 115
def parse_created_at(value) value = value.first if value.is_a?(Array) return unless value.is_a?(String) require "time" begin Time.iso8601(value) rescue ArgumentError nil end end
#pretty_print(q)
# File 'lib/rubygems/resolver/api_specification.rb', line 66
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
# File 'lib/rubygems/resolver/api_specification.rb', line 109
def source # :nodoc: @set.source end
#spec
A ::Gem::Specification stub built from the Compact Index data for this
specification. The compact index carries everything needed to
download and install the gem, so the Marshal gemspec is not fetched.
Development dependencies are not included; see
#fetch_development_dependencies.
# File 'lib/rubygems/resolver/api_specification.rb', line 94
def spec # :nodoc: @spec ||= Gem::Specification.new do |s| s.name = @name s.version = @version s.platform = @platform s.original_platform = @original_platform s.required_ruby_version = @required_ruby_version s.required_rubygems_version = @required_rubygems_version @dependencies.each do |dependency| s.add_runtime_dependency dependency.name, *dependency.requirement.as_list end end end