Class: Gem::NameTuple
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
Comparable
|
|
| Inherits: | Object |
| Defined in: | lib/rubygems/name_tuple.rb |
Overview
Represents a gem of name #name at #version of #platform, optionally carrying a #content_address and #ruby_abi for content-addressable gems. These wrap the data returned from the indexes.
Class Method Summary
-
.from_list(list)
Turn an array of tuples into an array of
NameTupleobjects. - .new(name, version, platform = Gem::Platform::RUBY, content_address: nil, ruby_abi: nil) ⇒ NameTuple constructor
-
.null
A null
NameTuple, ie name=nil, version=0. -
.to_basic(list)
Turn an array of
NameTupleobjects back into an array of [name, version, platform] tuples.
Instance Attribute Summary
- #content_address readonly
-
#match_platform? ⇒ Boolean
readonly
Indicate if this
NameTuplematches the current platform. - #name readonly
- #platform readonly
-
#prerelease? ⇒ Boolean
readonly
Indicate if this
NameTupleis for a prerelease version. - #ruby_abi readonly
- #version readonly
Instance Method Summary
- #<=>(other)
-
#==(other)
(also: #eql?)
Compare with
other. -
#deconstruct
Alias for #to_a.
- #deconstruct_keys(keys)
-
#eql?(other)
Alias for #==.
-
#full_name
Returns the full name (name-version) of this
::Gem. - #hash
-
#spec_name
Return the name that the gemspec file would be.
-
#to_a
(also: #deconstruct)
Convert back to the tuple array.
- #inspect (also: #to_s) Internal use only
- #sort_key Internal use only
-
#to_s
Internal use only
Alias for #inspect.
Constructor Details
.new(name, version, platform = Gem::Platform::RUBY, content_address: nil, ruby_abi: nil) ⇒ NameTuple
# File 'lib/rubygems/name_tuple.rb', line 10
def initialize(name, version, platform = Gem::Platform::RUBY, content_address: nil, ruby_abi: nil) @name = name @version = version platform &&= platform.to_s platform = Gem::Platform::RUBY if !platform || platform.empty? @platform = platform @content_address = content_address unless content_address.nil? @ruby_abi = ruby_abi unless ruby_abi.nil? end
Class Method Details
.from_list(list)
Turn an array of tuples into an array of NameTuple objects. Accepts:
NameTupleobjects (passed through as-is)- 3-element arrays: [name, version, platform]
- 5-element arrays: [name, version, platform, content_address, ruby_abi]
# File 'lib/rubygems/name_tuple.rb', line 29
def self.from_list(list) list.map do |tuple| case tuple when Gem::NameTuple tuple when Array case tuple.length when 3, 5 new(tuple[0], tuple[1], tuple[2], content_address: tuple[3], ruby_abi: tuple[4]) else raise ArgumentError, "Expected a 3- or 5-element tuple, got #{tuple.length}" end else raise ArgumentError, "Expected a Gem::NameTuple or Array, got #{tuple.class}" end end end
.null
A null NameTuple, ie name=nil, version=0
.to_basic(list)
Turn an array of NameTuple objects back into an array of
[name, version, platform] tuples.
Instance Attribute Details
#content_address (readonly)
[ GitHub ]
#match_platform? ⇒ Boolean (readonly)
Indicate if this NameTuple matches the current platform.
# File 'lib/rubygems/name_tuple.rb', line 80
def match_platform? Gem::Platform.match_gem? @platform, @name end
#name (readonly)
[ GitHub ]# File 'lib/rubygems/name_tuple.rb', line 21
attr_reader :name, :version, :platform, :content_address, :ruby_abi
#platform (readonly)
[ GitHub ]# File 'lib/rubygems/name_tuple.rb', line 21
attr_reader :name, :version, :platform, :content_address, :ruby_abi
#prerelease? ⇒ Boolean (readonly)
Indicate if this NameTuple is for a prerelease version.
# File 'lib/rubygems/name_tuple.rb', line 86
def prerelease? @version.prerelease? end
#ruby_abi (readonly)
[ GitHub ]# File 'lib/rubygems/name_tuple.rb', line 21
attr_reader :name, :version, :platform, :content_address, :ruby_abi
#version (readonly)
[ GitHub ]# File 'lib/rubygems/name_tuple.rb', line 21
attr_reader :name, :version, :platform, :content_address, :ruby_abi
Instance Method Details
#<=>(other)
[ GitHub ]#==(other) Also known as: #eql?
Compare with other. Supports another NameTuple or an Array
in the [name, version, platform, content_address, ruby_abi] format.
#deconstruct
Alias for #to_a.
# File 'lib/rubygems/name_tuple.rb', line 110
alias_method :deconstruct, :to_a
#deconstruct_keys(keys)
[ GitHub ]# File 'lib/rubygems/name_tuple.rb', line 112
def deconstruct_keys(keys) { name: @name, version: @version, platform: @platform, content_address: @content_address, ruby_abi: @ruby_abi, } end
#eql?(other)
Alias for #==.
# File 'lib/rubygems/name_tuple.rb', line 157
alias_method :eql?, :==
#full_name
#hash
[ GitHub ]# File 'lib/rubygems/name_tuple.rb', line 159
def hash to_a.hash end
#inspect Also known as: #to_s
# File 'lib/rubygems/name_tuple.rb', line 122
def inspect # :nodoc: "#<Gem::NameTuple name=#{@name} version=#{@version} platform=#{@platform} content_address=#{@content_address} ruby_abi=#{@ruby_abi}>" end
#sort_key
# File 'lib/rubygems/name_tuple.rb', line 132
def sort_key # :nodoc: [@name, @version, Gem::Platform.sort_priority(@platform), @content_address.to_s, @ruby_abi.to_s] end
#spec_name
Return the name that the gemspec file would be
# File 'lib/rubygems/name_tuple.rb', line 93
def spec_name "#{full_name}.gemspec" end
#to_a Also known as: #deconstruct
Convert back to the tuple array. Returns [name, version, platform] for non-content-addressable gems, or [name, version, platform, content_address, ruby_abi] for content-addressable gems.
# File 'lib/rubygems/name_tuple.rb', line 102
def to_a if @content_address [@name, @version, @platform, @content_address, @ruby_abi] else [@name, @version, @platform] end end
#to_s
Alias for #inspect.
# File 'lib/rubygems/name_tuple.rb', line 126
alias_method :to_s, :inspect # :nodoc: