Class: Gemvault::GemEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/gemvault/gem_entry.rb

Overview

Value object for one gem's identity (name, version, platform) and the time it was stored in a vault. Equality, hashing, and to_h come from Data.

Constant Summary collapse

RUBY_PLATFORM_NAME =
"ruby".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, version:, platform: RUBY_PLATFORM_NAME, created_at: nil) ⇒ GemEntry

Returns a new instance of GemEntry.



14
15
16
# File 'lib/gemvault/gem_entry.rb', line 14

def initialize(name:, version:, platform: RUBY_PLATFORM_NAME, created_at: nil)
  super
end

Class Method Details

.from_spec(spec, created_at: nil) ⇒ Object

Builds an entry from a Gem::Specification (or any object with name, version, and platform), stringifying the version and platform.



10
11
12
# File 'lib/gemvault/gem_entry.rb', line 10

def self.from_spec(spec, created_at: nil)
  new(name: spec.name, version: spec.version.to_s, platform: spec.platform.to_s, created_at:)
end

Instance Method Details

#filenameObject



24
# File 'lib/gemvault/gem_entry.rb', line 24

def filename = "#{full_name}.gem"

#full_nameObject



20
21
22
# File 'lib/gemvault/gem_entry.rb', line 20

def full_name
  ruby_platform? ? "#{name}-#{version}" : "#{name}-#{version}-#{platform}"
end

#ruby_platform?Boolean

Returns:

  • (Boolean)


18
# File 'lib/gemvault/gem_entry.rb', line 18

def ruby_platform? = platform == RUBY_PLATFORM_NAME

#same_identity_as?(other) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/gemvault/gem_entry.rb', line 26

def same_identity_as?(other)
  name == other.name && version == other.version && platform == other.platform
end

#to_sObject



30
31
32
# File 'lib/gemvault/gem_entry.rb', line 30

def to_s
  ruby_platform? ? "#{name}-#{version}" : "#{name}-#{version} (#{platform})"
end