Class: Undercover::Report

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/undercover.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Report

Initializes a new Undercover::Report

Parameters:



30
31
32
33
34
35
36
# File 'lib/undercover.rb', line 30

def initialize(opts)
  @lcov = LcovParser.parse(File.open(opts.lcov))
  @code_dir = opts.path
  git_dir = File.join(opts.path, opts.git_dir)
  @changeset = Changeset.new(git_dir, opts.compare).update
  @results = Hash.new { |hsh, key| hsh[key] = [] }
end

Instance Attribute Details

#changesetObject (readonly)

Returns the value of attribute changeset.



22
23
24
# File 'lib/undercover.rb', line 22

def changeset
  @changeset
end

#code_dirObject (readonly)

Returns the value of attribute code_dir.



22
23
24
# File 'lib/undercover.rb', line 22

def code_dir
  @code_dir
end

#lcovObject (readonly)

Returns the value of attribute lcov.



22
23
24
# File 'lib/undercover.rb', line 22

def lcov
  @lcov
end

#resultsObject (readonly)

Returns the value of attribute results.



22
23
24
# File 'lib/undercover.rb', line 22

def results
  @results
end

Instance Method Details

#all_resultsObject

rubocop:enable Metrics/MethodLength, Metrics/AbcSize



67
68
69
# File 'lib/undercover.rb', line 67

def all_results
  results.values.flatten
end

#buildObject



38
39
40
41
42
43
44
45
# File 'lib/undercover.rb', line 38

def build
  each_result_arg do |filename, coverage, imagen_node|
    results[filename.gsub(/^\.\//, '')] << Result.new(
      imagen_node, coverage, filename
    )
  end
  self
end

#build_warningsObject

TODO: this is experimental and might be incorrect! rubocop:disable Metrics/MethodLength, Metrics/AbcSize



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/undercover.rb', line 49

def build_warnings
  flagged_results = Set.new
  changeset.each_changed_line do |filepath, line_no|
    dist_from_line_no = lambda do |res|
      return BigDecimal::INFINITY if line_no < res.first_line
      line_no - res.first_line
    end
    dist_from_line_no_sorter = lambda do |res1, res2|
      dist_from_line_no[res1] <=> dist_from_line_no[res2]
    end

    res = results[filepath].min(&dist_from_line_no_sorter)
    flagged_results << res if res&.uncovered?(line_no)
  end
  flagged_results
end

#inspectObject Also known as: to_s



71
72
73
# File 'lib/undercover.rb', line 71

def inspect
  "#<Undercover::Report:#{object_id} results: #{results.size}>"
end