Class: BundleUpdateInteractive::Lockfile

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specs) ⇒ Lockfile

Returns a new instance of Lockfile.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bundle_update_interactive/lockfile.rb', line 13

def initialize(specs)
  @specs_by_name = {}
  required_exactly = Set.new

  specs.each do |spec|
    specs_by_name[spec.name] = spec
    spec.dependencies.each { |dep| required_exactly << dep.name if dep.requirement.exact? }
  end

  @entries_by_name = specs_by_name.transform_values do |spec|
    build_entry(spec, required_exactly.include?(spec.name))
  end
end

Class Method Details

.parse(lockfile_contents = File.read("Gemfile.lock")) ⇒ Object



8
9
10
11
# File 'lib/bundle_update_interactive/lockfile.rb', line 8

def self.parse(lockfile_contents=File.read("Gemfile.lock"))
  parser = Bundler::LockfileParser.new(lockfile_contents)
  new(parser.specs)
end

Instance Method Details

#[](gem_name) ⇒ Object



31
32
33
# File 'lib/bundle_update_interactive/lockfile.rb', line 31

def [](gem_name)
  entries_by_name[gem_name]
end

#entriesObject



27
28
29
# File 'lib/bundle_update_interactive/lockfile.rb', line 27

def entries
  entries_by_name.values
end

#gems_exclusively_installed_by(gemfile:, groups:) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/bundle_update_interactive/lockfile.rb', line 35

def gems_exclusively_installed_by(gemfile:, groups:)
  return [] if groups.empty?

  other_group_gems = gemfile.dependencies.filter_map { |gem| gem.name unless (gem.groups & groups).any? }
  other_group_gems &= entries_by_name.keys
  gems_installed_by_other_groups = other_group_gems + traverse_transient_dependencies(*other_group_gems)

  entries_by_name.keys - gems_installed_by_other_groups
end