class Gem::NameTuple

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.

Attributes

Public Class Methods

Turn an array of tuples into an array of NameTuple objects. Accepts:

# 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
# 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

A null NameTuple, ie name=nil, version=0

# File lib/rubygems/name_tuple.rb, line 58
def self.null
  new nil, Gem::Version.new(0), nil
end

Turn an array of NameTuple objects back into an array of

name, version, platform

tuples.

# File lib/rubygems/name_tuple.rb, line 51
def self.to_basic(list)
  list.map {|tuple| [tuple.name, tuple.version, tuple.platform] }
end

Public Instance Methods

# File lib/rubygems/name_tuple.rb, line 128
def <=>(other)
  sort_key <=> other.sort_key
end

Compare with other. Supports another NameTuple or an Array in the [name, version, platform, content_address, ruby_abi] format.

# File lib/rubygems/name_tuple.rb, line 142
def ==(other)
  case other
  when self.class
    @name == other.name &&
      @version == other.version &&
      @platform == other.platform &&
      @content_address == other.content_address &&
      @ruby_abi == other.ruby_abi
  when Array
    to_a == other
  else
    false
  end
end
Also aliased as: eql?
# 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
Alias for: ==

Returns the full name (name-version) of this Gem. Platform information is included if it is not the default Ruby platform. This mimics the behavior of Gem::Specification#full_name.

# File lib/rubygems/name_tuple.rb, line 67
def full_name
  if @content_address
    "#{@name}-#{@version}-#{@content_address}"
  elsif @platform.nil? || @platform.empty? || @platform == Gem::Platform::RUBY
    "#{@name}-#{@version}"
  else
    "#{@name}-#{@version}-#{@platform}"
  end
end
# File lib/rubygems/name_tuple.rb, line 159
def hash
  to_a.hash
end

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

Indicate if this NameTuple is for a prerelease version.

# File lib/rubygems/name_tuple.rb, line 86
def prerelease?
  @version.prerelease?
end

Return the name that the gemspec file would be

# File lib/rubygems/name_tuple.rb, line 93
def spec_name
  "#{full_name}.gemspec"
end

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
Also aliased as: deconstruct