Class: LockDiff::Gem::LockfileComparator

Inherits:
Object
  • Object
show all
Defined in:
lib/lock_diff/gem/lockfile_comparator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_lockfile:, new_lockfile:) ⇒ LockfileComparator

Returns a new instance of LockfileComparator.



11
12
13
14
# File 'lib/lock_diff/gem/lockfile_comparator.rb', line 11

def initialize(old_lockfile:, new_lockfile:)
  @old_lockfile = old_lockfile
  @new_lockfile = new_lockfile
end

Class Method Details

.compare_by(pr_gemfile_lock) ⇒ Object



4
5
6
7
8
9
# File 'lib/lock_diff/gem/lockfile_comparator.rb', line 4

def self.compare_by(pr_gemfile_lock)
  new(
    old_lockfile: pr_gemfile_lock.base_file,
    new_lockfile: pr_gemfile_lock.head_file
  ).call
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lock_diff/gem/lockfile_comparator.rb', line 16

def call
  old_specs_by_name = Spec.new(@old_lockfile).map { |spec| [spec.name, spec] }.to_h
  new_specs_by_name = Spec.new(@new_lockfile).map { |spec| [spec.name, spec] }.to_h
  names = (old_specs_by_name.keys + new_specs_by_name.keys).uniq

  names.map { |name|
    DiffInfo.new(
      old_package: (old_specs_by_name[name] || NullSpec.new(name)).to_package,
      new_package: (new_specs_by_name[name] || NullSpec.new(name)).to_package
    )
  }.select(&:changed?)
end