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: a tar archive of .gem files indexed by a manifest. Legacy SQLite vaults are read transparently.

Used by the gemvault RubyGems plugin to support:

gem install --source myvault.gemv activesupport

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Vault

Returns a new instance of Vault.



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

def initialize(path)
  resolved = Gemvault::VaultPath.resolve(path)
  @path = Pathname(resolved).expand_path.to_s
  super(@path)
  @uri = @path
  @specs = nil
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

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



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

def download(spec, dir = Dir.pwd)
  verbose "Extracting #{spec.file_name} from vault at #{@path}"
  dest = Pathname(dir).join("cache").tap(&:mkpath).join(spec.file_name)

  Gemvault::Vault.open(@path) do |vault|
    entry = entry_for(spec)
    bytes = vault.gem_data(entry)
    dest.binwrite(bytes)
  end

  dest.to_s
end

#fetch_spec(name_tuple) ⇒ Object

Raises:

  • (Gem::Exception)


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

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



26
27
28
29
30
# File 'lib/rubygems/source/vault.rb', line 26

def load_specs(type)
  verbose "Loading #{type} specs from vault at #{@path}"
  ensure_specs_loaded
  select_candidates(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