Class: Bundler::Plugin::VaultSource

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

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ VaultSource

Returns a new instance of VaultSource.



7
8
9
10
11
# File 'lib/bundler/plugin/vault_source.rb', line 7

def initialize(opts)
  super
  @vault_path = resolve_vault_path(@uri)
  validate_vault_exists!
end

Instance Method Details

#fetch_gemspec_filesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bundler/plugin/vault_source.rb', line 13

def fetch_gemspec_files
  gemspec_files = []

  Gemvault::Vault.open(@vault_path) do |vault|
    vault.gem_entries.each do |entry|
      spec = vault.spec_from_blob(entry.name, entry.version, entry.platform)
      full_name = spec.full_name
      spec_ruby = spec.to_ruby

      gem_dir = gem_dir_for(full_name)
      if File.directory?(gem_dir)
        gemspec_files << anchor_gemspec(gem_dir, full_name, spec_ruby)
      else
        gemspec_dir = File.join(Bundler.tmp("vault_source"), "specifications")
        FileUtils.mkdir_p(gemspec_dir)
        gemspec_path = File.join(gemspec_dir, "#{full_name}.gemspec")
        File.write(gemspec_path, spec_ruby)
        gemspec_files << gemspec_path
      end
    end
  end

  gemspec_files
end

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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bundler/plugin/vault_source.rb', line 38

def install(spec, opts = {})
  gem_dir = gem_dir_for(spec.full_name)
  if File.directory?(gem_dir) && !opts[:force]
    Bundler.ui.debug "Using #{version_message(spec)} from vault #{File.basename(@vault_path)}"
    gemspec_in_gem = File.join(gem_dir, "#{spec.full_name}.gemspec")
    spec.full_gem_path = gem_dir
    spec.loaded_from = gemspec_in_gem
    return nil
  end

  Bundler.ui.confirm "Installing #{version_message(spec)} from vault #{File.basename(@vault_path)}"

  Gemvault::Vault.open(@vault_path) do |vault|
    vault.with_gem_file(spec.name, spec.version.to_s, platform: spec.platform.to_s) do |gem_path|
      require "bundler/rubygems_gem_installer"

      installer = Bundler::RubyGemsGemInstaller.at(
        gem_path,
        install_dir: Bundler.bundle_path.to_s,
        bin_dir: Bundler.system_bindir.to_s,
        ignore_dependencies: true,
        wrappers: true,
        env_shebang: true,
        build_args: opts[:build_args] || [],
      )

      installed_spec = installer.install

      gem_dir = installed_spec.full_gem_path
      spec.full_gem_path = gem_dir
      spec.loaded_from = anchor_gemspec(gem_dir, spec.full_name, installed_spec.to_ruby)
    end
  end

  spec.post_install_message
end

#options_to_lockObject



75
76
77
# File 'lib/bundler/plugin/vault_source.rb', line 75

def options_to_lock
  {}
end

#to_sObject



79
80
81
# File 'lib/bundler/plugin/vault_source.rb', line 79

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