123456789_123456789_123456789_123456789_123456789_

Class: SimpleCov::FileList

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Forwardable
Instance Chain:
self, Enumerable
Inherits: Object
Defined in: lib/simplecov/file_list.rb

Overview

An array of ::SimpleCov SourceFile instances with additional collection helper methods for calculating coverage across them etc.

Class Method Summary

Instance Method Summary

Constructor Details

.new(files) ⇒ FileList

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 22

def initialize(files)
  @files = files
end

Instance Method Details

#branch_covered_percent

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 101

def branch_covered_percent
  coverage_statistics[:branch]&.percent
end

#compute_coverage_statistics (private)

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 114

def compute_coverage_statistics
  coverage_statistics = {line: CoverageStatistics.from(coverage_statistics_by_file[:line])}
  coverage_statistics[:branch] = CoverageStatistics.from(coverage_statistics_by_file[:branch]) if SimpleCov.branch_coverage?
  coverage_statistics
end

#compute_coverage_statistics_by_file (private)

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 107

def compute_coverage_statistics_by_file
  @files.each_with_object(line: [], branch: []) do |file, together|
    together[:line] << file.coverage_statistics.fetch(:line)
    together[:branch] << file.coverage_statistics.fetch(:branch) if SimpleCov.branch_coverage?
  end
end

#coverage_statistics

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 26

def coverage_statistics
  @coverage_statistics ||= compute_coverage_statistics
end

#coverage_statistics_by_file

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 30

def coverage_statistics_by_file
  @coverage_statistics_by_file ||= compute_coverage_statistics_by_file
end

#covered_branches

Return total count of covered branches

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 92

def covered_branches
  coverage_statistics[:branch]&.covered
end

#covered_lines

Returns the count of lines that have coverage

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 35

def covered_lines
  coverage_statistics[:line]&.covered
end

#covered_percentFloat

Computes the coverage based upon lines covered and lines missed

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 76

def covered_percent
  coverage_statistics[:line]&.percent
end

#covered_percentages

Computes the coverage based upon lines covered and lines missed for each file Returns an array with all coverage percentages

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 60

def covered_percentages
  map(&:covered_percent)
end

#covered_strengthFloat

Computes the strength (hits / line) based upon lines covered and lines missed

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 82

def covered_strength
  coverage_statistics[:line]&.strength
end

#least_covered_file

Finds the least covered file and returns that file’s name

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 65

def least_covered_file
  min_by(&:covered_percent).filename
end

#lines_of_code

Returns the overall amount of relevant lines of code across all files in this list

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 70

def lines_of_code
  coverage_statistics[:line]&.total
end

#missed_branches

Return total count of covered branches

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 97

def missed_branches
  coverage_statistics[:branch]&.missed
end

#missed_lines

Returns the count of lines that have been missed

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 40

def missed_lines
  coverage_statistics[:line]&.missed
end

#never_lines

Returns the count of lines that are not relevant for coverage

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 45

def never_lines
  return 0.0 if empty?

  map { |f| f.never_lines.count }.inject(:+)
end

#skipped_lines

Returns the count of skipped lines

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 52

def skipped_lines
  return 0.0 if empty?

  map { |f| f.skipped_lines.count }.inject(:+)
end

#total_branches

Return total count of branches in all files

[ GitHub ]

  
# File 'lib/simplecov/file_list.rb', line 87

def total_branches
  coverage_statistics[:branch]&.total
end