class Undercover::Changeset
Base class for different kinds of input
Constants
- T_ZERO
Attributes
compare_base[R]
files[R]
repo[R]
Public Class Methods
new(dir, compare_base = nil)
click to toggle source
# File lib/undercover/changeset.rb, line 18 def initialize(dir, compare_base = nil) @dir = dir @repo = Rugged::Repository.new(dir) @repo.workdir = Pathname.new(dir).dirname.to_s # TODO: can replace? @compare_base = compare_base @files = {} end
Public Instance Methods
each_changed_line() { |filepath, ln| ... }
click to toggle source
# File lib/undercover/changeset.rb, line 52 def each_changed_line files.each do |filepath, line_numbers| line_numbers.each { |ln| yield filepath, ln } end end
file_paths()
click to toggle source
# File lib/undercover/changeset.rb, line 48 def file_paths files.keys.sort end
last_modified()
click to toggle source
# File lib/undercover/changeset.rb, line 38 def last_modified mod = file_paths.map do |f| path = File.join(repo.workdir, f) next T_ZERO unless File.exist?(path) File.mtime(path) end.max mod || T_ZERO end
update()
click to toggle source
# File lib/undercover/changeset.rb, line 26 def update full_diff.each_patch do |patch| filepath = patch.delta.new_file[:path] line_nums = patch.each_hunk.map do |hunk| # TODO: optimise this to use line ranges! hunk.lines.select(&:addition?).map(&:new_lineno) end.flatten @files[filepath] = line_nums if line_nums.any? end self end
validate(lcov_report_path)
click to toggle source
TODO: refactor to a standalone validator (depending on changeset AND lcov) TODO: add specs
# File lib/undercover/changeset.rb, line 60 def validate(lcov_report_path) return :no_changes if files.empty? return :stale_coverage if last_modified > File.mtime(lcov_report_path) end
Private Instance Methods
compare_base_obj()
click to toggle source
# File lib/undercover/changeset.rb, line 74 def compare_base_obj return nil unless compare_base repo.lookup(repo.merge_base(compare_base.to_s, head)) end
full_diff()
click to toggle source
Diffs `head` or `head` + `compare_base` (if exists), as it makes sense to run Undercover
with the most recent file versions
# File lib/undercover/changeset.rb, line 69 def full_diff base = compare_base_obj || head base.diff(repo.index).merge!(repo.diff_workdir(head)) end
head()
click to toggle source
# File lib/undercover/changeset.rb, line 80 def head repo.head.target end