Class: Gem::Source::Vault
- Inherits:
-
Gem::Source
- Object
- Gem::Source
- Gem::Source::Vault
- 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
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #dependency_resolver_set(prerelease = false) ⇒ Object
- #download(spec, dir = Dir.pwd) ⇒ Object
- #fetch_spec(name_tuple) ⇒ Object
- #hash ⇒ Object
-
#initialize(path) ⇒ Vault
constructor
A new instance of Vault.
- #load_specs(type) ⇒ Object
- #pretty_print(q) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ Vault
Returns a new instance of Vault.
15 16 17 18 19 20 21 |
# File 'lib/rubygems/source/vault.rb', line 15 def initialize(path) path = path.to_s path = path.sub(%r{^file://}, "") if path.start_with?("file://") @path = File.(path) @uri = @path @specs = nil end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/rubygems/source/vault.rb', line 13 def path @path end |
Instance Method Details
#<=>(other) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubygems/source/vault.rb', line 73 def <=>(other) case other when Gem::Source::Installed, Gem::Source::Lock then -1 when Gem::Source::Vault 0 when Gem::Source::Local -1 when Gem::Source 1 end end |
#==(other) ⇒ Object Also known as: eql?
87 88 89 |
# File 'lib/rubygems/source/vault.rb', line 87 def ==(other) other.is_a?(self.class) && @path == other.path end |
#dependency_resolver_set(prerelease = false) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/rubygems/source/vault.rb', line 66 def dependency_resolver_set(prerelease = false) require_relative "../resolver/vault_set" set = Gem::Resolver::VaultSet.new(self) set.prerelease = prerelease set end |
#download(spec, dir = Dir.pwd) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rubygems/source/vault.rb', line 51 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
42 43 44 45 46 47 48 49 |
# File 'lib/rubygems/source/vault.rb', line 42 def fetch_spec(name_tuple) ensure_specs_loaded spec = @specs[name_tuple] raise Gem::Exception, "Unable to find '#{name_tuple}'" unless spec spec end |
#hash ⇒ Object
93 94 95 |
# File 'lib/rubygems/source/vault.rb', line 93 def hash @path.hash end |
#load_specs(type) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubygems/source/vault.rb', line 23 def load_specs(type) verbose "Loading #{type} specs from vault at #{@path}" ensure_specs_loaded case type when :released @specs.keys.reject { |t| t.version.prerelease? } when :prerelease @specs.keys.select { |t| t.version.prerelease? } when :latest @specs.keys .group_by { |tuple| [tuple.name, tuple.platform] } .values .map { |tuples| tuples.max_by(&:version) } else @specs.keys end end |
#pretty_print(q) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/rubygems/source/vault.rb', line 101 def pretty_print(q) q.object_group(self) do q.group 2, "[Vault:", "]" do q.breakable q.text @path end end end |
#to_s ⇒ Object
97 98 99 |
# File 'lib/rubygems/source/vault.rb', line 97 def to_s "vault at #{@path}" end |