Class: Bundler::Plugin::VaultSource

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/plugin/vault_source.rb

Overview

Bundler plugin source that installs gems from a .gemv vault file. A thin doorway over the Bundler Source API: it resolves the vault path, hands Bundler the gemspecs it can install, and delegates each gem's placement in the bundle to a VaultedGem.

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ VaultSource

Returns a new instance of VaultSource.



13
14
15
16
17
# File 'lib/bundler/plugin/vault_source.rb', line 13

def initialize(opts)
  super
  @vault_path = Pathname(@uri).expand_path(Bundler.root)
  @allow_remote = false
end

Instance Method Details

#cache(spec, custom_path = nil) ⇒ Object

No source-level install_path to copy: VaultSource#install installs each gem into Bundler.bundle_path via RubyGemsGemInstaller, so the default Source#cache would dereference a non-existent directory.



69
# File 'lib/bundler/plugin/vault_source.rb', line 69

def cache(spec, custom_path = nil); end

#fetch_gemspec_filesObject



19
20
21
22
23
24
25
26
27
# File 'lib/bundler/plugin/vault_source.rb', line 19

def fetch_gemspec_files
  validate_vault_exists!

  Gemvault::Vault.open(@vault_path) do |vault|
    vault.gem_entries
         .map { |entry| vault.spec_from_blob(entry) }
         .filter_map { |spec| gemspec_file_for(spec) }
  end
end

#install(spec, opts = {}) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/bundler/plugin/vault_source.rb', line 54

def install(spec, opts = {})
  gem = VaultedGem.new(spec)
  return gem.adopt if gem.installed? && !opts[:force]

  Bundler.ui.confirm "Installing #{gem.version_message} from vault #{@uri}"
  extract(spec) { |gem_path| gem.install(gem_path:, build_args: opts[:build_args] || []) }
end

#local_only!Object

The inverse of remote!. Bundler's local-only resolve (Definition#check!, reached by bundle check) calls local_only! on every source. The base Bundler::Plugin::API::Source defines no such hook, so without this the command dies with NoMethodError; here it simply stops advertising gems that live only inside the archive.



45
46
47
# File 'lib/bundler/plugin/vault_source.rb', line 45

def local_only!
  @allow_remote = false
end

#options_to_lockObject



62
63
64
# File 'lib/bundler/plugin/vault_source.rb', line 62

def options_to_lock
  {}
end

#prefer_local!Object

Also invoked on every source during resolution (Definition#prefer_local!, for --prefer-local). The vault reads from one local file already, so there is no remote to deprioritize.



52
# File 'lib/bundler/plugin/vault_source.rb', line 52

def prefer_local!; end

#remote!Object

Bundler first asks a source, in local mode, which gems are already unpacked so it can tell what still needs installing, then switches to remote mode to resolve and install the rest. A vault gem is not on the load path until it is unpacked, so advertising one that still lives only inside the archive makes Bundler believe it is installed: it skips the install and the later require fails. Advertise not-yet-unpacked gems only once Bundler has asked for remote specs.



36
37
38
# File 'lib/bundler/plugin/vault_source.rb', line 36

def remote!
  @allow_remote = true
end

#to_sObject



71
72
73
# File 'lib/bundler/plugin/vault_source.rb', line 71

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