class Unwrappr::LockFileDiff
Responsible for identifying all gem changes between two versions of a Gemfile.lock file.
Attributes
filename[R]
sha[R]
Public Class Methods
new(filename:, base_file:, head_file:, patch:, sha:)
click to toggle source
# File lib/unwrappr/lock_file_diff.rb, line 7 def initialize(filename:, base_file:, head_file:, patch:, sha:) @filename = filename @base_file = base_file @head_file = head_file @patch = patch @sha = sha end
Public Instance Methods
each_gem_change() { |gem_change( name: change, base_version: gem_version(change), head_version: gem_version(change), line_number: line_number_for_change(change), lock_file_diff: self| ... }
click to toggle source
# File lib/unwrappr/lock_file_diff.rb, line 17 def each_gem_change version_changes.each do |change| yield GemChange.new( name: change[:dependency].to_s, base_version: gem_version(change[:before]), head_version: gem_version(change[:after]), line_number: line_number_for_change(change), lock_file_diff: self ) end end
Private Instance Methods
extract_gem_and_change_type(line)
click to toggle source
# File lib/unwrappr/lock_file_diff.rb, line 61 def extract_gem_and_change_type(line) # We only care about lines like this: # '+ websocket-driver (0.6.5)' # Careful not to match this (note the wider indent): # '+ websocket-extensions (>= 0.1.0)' pattern = /^(?<change_type>[+\-]) (?<gem_name>\S+) \(\d/ match = pattern.match(line) return match[:gem_name], match[:change_type] unless match.nil? end
gem_version(version)
click to toggle source
# File lib/unwrappr/lock_file_diff.rb, line 36 def gem_version(version) version && GemVersion.new(version) end
line_number_for_change(change)
click to toggle source
Obtain the line in the patch that should be annotated
# File lib/unwrappr/lock_file_diff.rb, line 41 def line_number_for_change(change) # If a gem is removed, use the `-` line (as there is no `+` line). # For all other cases use the `+` line. type = (change[:after].nil? ? '-' : '+') line_numbers[change[:dependency].to_s][type] end
line_numbers()
click to toggle source
# File lib/unwrappr/lock_file_diff.rb, line 48 def line_numbers return @line_numbers if defined?(@line_numbers) @line_numbers = Hash.new { |hash, key| hash[key] = {} } @patch.split("\n").each_with_index do |line, line_number| gem_name, change_type = extract_gem_and_change_type(line) next if gem_name.nil? || change_type.nil? @line_numbers[gem_name][change_type] = line_number end @line_numbers end
version_changes()
click to toggle source
# File lib/unwrappr/lock_file_diff.rb, line 31 def version_changes @version_changes ||= LockFileComparator.perform(@base_file, @head_file)[:versions] end