Class: Gemvault::Tarvault
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
open
#spec_from_blob, #specs, #with_gem_file
Constructor Details
#initialize(path, create: false) ⇒ Tarvault
Returns a new instance of Tarvault.
21
22
23
24
25
26
|
# File 'lib/gemvault/tarvault.rb', line 21
def initialize(path, create: false)
@path = Pathname(path).expand_path
@archive = Tarball.new(@path)
@closed = false
create ? create_vault! : load_manifest!
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
19
20
21
|
# File 'lib/gemvault/tarvault.rb', line 19
def path
@path
end
|
Instance Method Details
#add(gem_path, created_at: nil) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/gemvault/tarvault.rb', line 28
def add(gem_path, created_at: nil)
gem_path = Pathname(gem_path).expand_path
raise Vault::NotFoundError, "Gem file not found: #{gem_path}" unless gem_path.file?
spec = spec_from_gem_file(gem_path)
entry = GemEntry.from_spec(spec, created_at: created_at || timestamp)
raise_if_duplicate(entry)
store(entry:, bytes: gem_path.binread)
end
|
#close ⇒ Object
70
71
72
|
# File 'lib/gemvault/tarvault.rb', line 70
def close
@closed = true
end
|
#closed? ⇒ Boolean
74
75
76
|
# File 'lib/gemvault/tarvault.rb', line 74
def closed?
@closed
end
|
62
63
64
|
# File 'lib/gemvault/tarvault.rb', line 62
def format_version
@manifest.format_version
end
|
#gem_data(entry) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/gemvault/tarvault.rb', line 48
def gem_data(entry)
record = @manifest.find(entry)
raise Vault::NotFoundError, "Gem not found: #{entry}" unless record
bytes = @archive.read(record.filename)
raise Vault::Error, "Integrity check failed for #{record.filename}" unless record.matches?(bytes)
bytes
end
|
#gem_entries ⇒ Object
58
59
60
|
# File 'lib/gemvault/tarvault.rb', line 58
def gem_entries
@manifest.gem_entries
end
|
#remove(reference) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/gemvault/tarvault.rb', line 38
def remove(reference)
dropped = @manifest.matching(reference)
return 0 if dropped.empty?
@manifest = @manifest.without(dropped)
remaining = survivors_excluding(dropped)
rewrite(remaining)
dropped.size
end
|
#size ⇒ Object
66
67
68
|
# File 'lib/gemvault/tarvault.rb', line 66
def size
@manifest.size
end
|