Class: Gemvault::Tarvault

Inherits:
Object
  • Object
show all
Extended by:
VaultSession
Includes:
GemExtraction
Defined in:
lib/gemvault/tarvault.rb

Overview

A Tarvault: a tarball whose first entry is manifest.json and whose remaining entries are .gem files. Portable, dependency-free storage.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VaultSession

open

Methods included from GemExtraction

#spec_from_blob, #specs, #with_gem_file

Constructor Details

#initialize(path, create: false) ⇒ Tarvault

Returns a new instance of Tarvault.



19
20
21
22
23
24
# File 'lib/gemvault/tarvault.rb', line 19

def initialize(path, create: false)
  @path = File.expand_path(path)
  @archive = TarArchive.new(@path)
  @closed = false
  create ? create_vault! : load_manifest!
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/gemvault/tarvault.rb', line 17

def path
  @path
end

Instance Method Details

#add(gem_path, created_at: nil) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/gemvault/tarvault.rb', line 26

def add(gem_path, created_at: nil)
  gem_path = File.expand_path(gem_path)
  raise Vault::NotFoundError, "Gem file not found: #{gem_path}" unless File.file?(gem_path)

  spec = spec_from_gem_file(gem_path)
  raise_if_duplicate(spec)
  store(spec, File.binread(gem_path), created_at || timestamp)
end

#closeObject



63
64
65
# File 'lib/gemvault/tarvault.rb', line 63

def close
  @closed = true
end

#closed?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/gemvault/tarvault.rb', line 67

def closed?
  @closed
end

#format_versionObject



55
56
57
# File 'lib/gemvault/tarvault.rb', line 55

def format_version
  @manifest.format_version
end

#gem_data(name, version, platform: "ruby") ⇒ Object



44
45
46
47
48
49
# File 'lib/gemvault/tarvault.rb', line 44

def gem_data(name, version, platform: "ruby")
  record = @manifest.find(name, version, platform)
  raise Vault::NotFoundError, "Gem not found: #{name}-#{version} (#{platform})" unless record

  verify(@archive.read(record.filename), record)
end

#gem_entriesObject



51
52
53
# File 'lib/gemvault/tarvault.rb', line 51

def gem_entries
  @manifest.gem_entries
end

#remove(reference) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/gemvault/tarvault.rb', line 35

def remove(reference)
  dropped = matching_records(reference)
  return 0 if dropped.empty?

  @manifest = @manifest.without(dropped)
  rewrite(survivors_excluding(dropped))
  dropped.size
end

#sizeObject



59
60
61
# File 'lib/gemvault/tarvault.rb', line 59

def size
  @manifest.records.size
end