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.



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

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#addObject



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

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

#closeObject



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

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

#closed?Boolean

Returns:

  • (Boolean)


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

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

#format_versionObject



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_entriesObject



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

#removeObject



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

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

#sizeObject



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

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