Class: Gem::Source::Vault

Inherits:
Gem::Source
  • Object
show all
Includes:
UserInteraction
Defined in:
lib/rubygems/source/vault.rb

Overview

A source backed by a .gemv vault file (SQLite archive of .gem blobs).

Used by the gemvault RubyGems plugin to support:

gem install --source myvault.gemv activesupport

Constant Summary collapse

VAULT_URI_SCHEMES =
%w[file vault].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Vault

Returns a new instance of Vault.



17
18
19
20
21
22
# File 'lib/rubygems/source/vault.rb', line 17

def initialize(path)
  @path = File.expand_path(filesystem_path(path))
  super(@path)
  @uri = @path
  @specs = nil
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/rubygems/source/vault.rb', line 15

def path
  @path
end

Instance Method Details

#<=>(other) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/rubygems/source/vault.rb', line 61

def <=>(other)
  case other
  when Gem::Source::Installed, Gem::Source::Lock, Gem::Source::Local then -1
  when Gem::Source::Vault then 0
  when Gem::Source then 1
  end
end

#==(other) ⇒ Object Also known as: eql?



69
70
71
# File 'lib/rubygems/source/vault.rb', line 69

def ==(other)
  other.is_a?(self.class) && @path == other.path
end

#dependency_resolver_set(prerelease = nil) ⇒ Object



54
55
56
57
58
59
# File 'lib/rubygems/source/vault.rb', line 54

def dependency_resolver_set(prerelease = nil)
  require_relative "../resolver/vault_set"
  set = Gem::Resolver::VaultSet.new(self)
  set.prerelease = prerelease
  set
end

#download(spec, dir = Dir.pwd) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubygems/source/vault.rb', line 39

def download(spec, dir = Dir.pwd)
  verbose "Extracting #{spec.file_name} from vault at #{@path}"
  cache_dir = File.join(dir, "cache")
  FileUtils.mkdir_p(cache_dir)

  dest = File.join(cache_dir, spec.file_name)

  Gemvault::Vault.open(@path) do |vault|
    data = vault.gem_data(spec.name, spec.version.to_s, platform: spec.platform.to_s)
    File.binwrite(dest, data)
  end

  dest
end

#fetch_spec(name_tuple) ⇒ Object

Raises:

  • (Gem::Exception)


30
31
32
33
34
35
36
37
# File 'lib/rubygems/source/vault.rb', line 30

def fetch_spec(name_tuple)
  ensure_specs_loaded

  spec = @specs[name_tuple]
  raise Gem::Exception, "Unable to find '#{name_tuple}'" unless spec

  spec
end

#hashObject



75
76
77
# File 'lib/rubygems/source/vault.rb', line 75

def hash
  @path.hash
end

#load_specs(type) ⇒ Object



24
25
26
27
28
# File 'lib/rubygems/source/vault.rb', line 24

def load_specs(type)
  verbose "Loading #{type} specs from vault at #{@path}"
  ensure_specs_loaded
  select_tuples(type)
end

#pretty_print(pp) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/rubygems/source/vault.rb', line 83

def pretty_print(pp)
  pp.object_group(self) do
    pp.group 2, "[Vault:", "]" do
      pp.breakable
      pp.text @path
    end
  end
end

#to_sObject



79
80
81
# File 'lib/rubygems/source/vault.rb', line 79

def to_s
  "vault at #{@path}"
end