Class: Gemvault::Dbvault
Overview
Read-only reader for a SQLite-backed vault (a "Dbvault"). Attempts to write
are refused with a pointer to run gemvault upgrade, and opening a vault
emits a one-time notice.
Constant Summary
collapse
- FORMAT_VERSION =
1
Instance Attribute Summary collapse
Instance Method Summary
collapse
open
#spec_from_blob, #specs, #with_gem_file
Constructor Details
#initialize(path) ⇒ Dbvault
Returns a new instance of Dbvault.
21
22
23
24
|
# File 'lib/gemvault/dbvault.rb', line 21
def initialize(path)
@path = Pathname(path).expand_path
open_vault!
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
19
20
21
|
# File 'lib/gemvault/dbvault.rb', line 19
def path
@path
end
|
Instance Method Details
#add ⇒ Object
26
27
28
|
# File 'lib/gemvault/dbvault.rb', line 26
def add(*)
raise Vault::ReadOnlyError, read_only_message
end
|
#close ⇒ Object
54
55
56
|
# File 'lib/gemvault/dbvault.rb', line 54
def close
@db.close if @db && !@db.closed?
end
|
#closed? ⇒ Boolean
58
59
60
|
# File 'lib/gemvault/dbvault.rb', line 58
def closed?
@db.nil? || @db.closed?
end
|
62
63
64
65
66
67
|
# File 'lib/gemvault/dbvault.rb', line 62
def format_version
row = @db.execute("SELECT value FROM metadata WHERE key = 'vault_version'").first
return FORMAT_VERSION unless row
row["value"].to_i
end
|
#gem_data(entry) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/gemvault/dbvault.rb', line 34
def gem_data(entry)
row = @db.execute(
"SELECT data FROM gems WHERE name = ? AND version = ? AND platform = ?",
[entry.name, entry.version, entry.platform],
).first
raise Vault::NotFoundError, "Gem not found: #{entry}" unless row
row["data"]
end
|
#gem_entries ⇒ Object
44
45
46
47
48
|
# File 'lib/gemvault/dbvault.rb', line 44
def gem_entries
@db.execute(
"SELECT name, version, platform, created_at FROM gems ORDER BY name, version",
).map { |row| GemEntry.new(**row.transform_keys(&:to_sym)) }
end
|
#remove ⇒ Object
30
31
32
|
# File 'lib/gemvault/dbvault.rb', line 30
def remove(*)
raise Vault::ReadOnlyError, read_only_message
end
|
#size ⇒ Object
50
51
52
|
# File 'lib/gemvault/dbvault.rb', line 50
def size
@db.execute("SELECT COUNT(*) AS count FROM gems").first["count"]
end
|