Class: Bundler::InstallDashDocs::Lockfile

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/install_dash_docs/lockfile.rb

Overview

Reads & parses a Gemfile.lock Lockfile, to extract the gems listed in it

Note that some gems may be listed multiple times, with different versions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lockfile_contents = nil) ⇒ Lockfile

Constructor that parses gem names and versions from the Lockfile

Parameters:

  • lockfile_contents (String, nil) (defaults to: nil)

    if non-nil, this string’s contents are used instead of the Bundler.default_lockfile



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bundler/install_dash_docs/lockfile.rb', line 22

def initialize(lockfile_contents = nil)
  lockfile_contents ||= Bundler.default_lockfile.read
  @parser = Bundler::LockfileParser.new(lockfile_contents)

  # dictionary of gem name to array of Bundler::LazySpecification
  @specs = @parser.specs.group_by(&:name)

  # create arrays of [name, version] pairs for all specs,
  # and only for dependencies from Gemfile
  @all_gems, @dependencies = [
    @specs,
    @parser.dependencies
  ].map { |hash|
    hash.keys
      .sort
      .flat_map { |name|
      versions_for_name(name).map { |version| [name, version] }
    }
  }
end

Instance Attribute Details

#all_gemsObject (readonly)

Array of [gem_name, version] pairs that includes all gems from the Lockfile



16
17
18
# File 'lib/bundler/install_dash_docs/lockfile.rb', line 16

def all_gems
  @all_gems
end

#dependenciesObject (readonly)

Array of [gem_name, version] pairs that are listed in the Dependencies section. Most likely ones that’re specifically requested by the Gemfile



13
14
15
# File 'lib/bundler/install_dash_docs/lockfile.rb', line 13

def dependencies
  @dependencies
end