Class: Gemvault::Dbvault

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

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

Methods included from VaultSession

open

Methods included from GemExtraction

#spec_from_blob, #specs, #with_gem_file

Constructor Details

#initialize(path) ⇒ Dbvault

Returns a new instance of Dbvault.



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

def initialize(path)
  @path = File.expand_path(path)
  open_vault!
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/gemvault/dbvault.rb', line 18

def path
  @path
end

Instance Method Details

#addObject



25
26
27
# File 'lib/gemvault/dbvault.rb', line 25

def add(*)
  raise Vault::ReadOnlyError, read_only_message
end

#closeObject



53
54
55
# File 'lib/gemvault/dbvault.rb', line 53

def close
  @db.close if @db && !@db.closed?
end

#closed?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/gemvault/dbvault.rb', line 57

def closed?
  @db.nil? || @db.closed?
end

#format_versionObject



61
62
63
64
# File 'lib/gemvault/dbvault.rb', line 61

def format_version
  row = @db.execute("SELECT value FROM metadata WHERE key = 'vault_version'").first
  row ? row["value"].to_i : FORMAT_VERSION
end

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



33
34
35
36
37
38
39
40
41
# File 'lib/gemvault/dbvault.rb', line 33

def gem_data(name, version, platform: "ruby")
  row = @db.execute(
    "SELECT data FROM gems WHERE name = ? AND version = ? AND platform = ?",
    [name, version, platform],
  ).first
  raise Vault::NotFoundError, "Gem not found: #{name}-#{version} (#{platform})" unless row

  row["data"]
end

#gem_entriesObject



43
44
45
46
47
# File 'lib/gemvault/dbvault.rb', line 43

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

#removeObject



29
30
31
# File 'lib/gemvault/dbvault.rb', line 29

def remove(*)
  raise Vault::ReadOnlyError, read_only_message
end

#sizeObject



49
50
51
# File 'lib/gemvault/dbvault.rb', line 49

def size
  @db.execute("SELECT COUNT(*) AS count FROM gems").first["count"]
end