Class: SimpleCov::FileList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, Enumerable[SimpleCov::SourceFile]
Defined in:
lib/simplecov/file_list.rb,
sig/simplecov.rbs

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ FileList

Returns a new instance of FileList.

Parameters:



12
13
14
# File 'lib/simplecov/file_list.rb', line 12

def initialize(files)
  @files = files
end

Instance Method Details

#branch_covered_percentFloat?

Returns:

  • (Float, nil)


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

def branch_covered_percent
  coverage_statistics[:branch]&.percent
end

#compute_coverage_statisticsHash[criterion, CoverageStatistics]

Returns:



120
121
122
# File 'lib/simplecov/file_list.rb', line 120

def compute_coverage_statistics
  coverage_statistics_by_file.transform_values { |stats| CoverageStatistics.from(stats) }
end

#compute_coverage_statistics_by_fileHash[criterion, Array[CoverageStatistics]]

Seeded with one entry per criterion the user enabled, so an empty FileList still yields the right shape. SourceFile#coverage_statistics always reports all three criteria; FileList is the layer that filters to the enabled set so disabled criteria don't surface in totals, JSON, or the HTML report.

Returns:



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/simplecov/file_list.rb', line 108

def compute_coverage_statistics_by_file
  seed = enabled_criteria_for_reporting.to_h do |criterion|
    bucket = [] #: Array[CoverageStatistics]
    [criterion, bucket]
  end
  each_with_object(seed) do |file, together|
    file.coverage_statistics.each do |criterion, stats|
      together.fetch(criterion) << stats if together.key?(criterion)
    end
  end
end

#countInteger #count(arg0) ⇒ Integer #countInteger

Overloads:

  • #countInteger

    Returns:

    • (Integer)
  • #count(arg0) ⇒ Integer

    Parameters:

    • arg0 (Object)

    Returns:

    • (Integer)
  • #countInteger

    Returns:

    • (Integer)

Yields:

Yield Parameters:

Yield Returns:

  • (boolish)


756
757
758
# File 'sig/simplecov.rbs', line 756

def count: () -> Integer
| (untyped) -> Integer
| () { (SourceFile) -> boolish } -> Integer

#coverage_statisticsHash[criterion, CoverageStatistics] #coverage_statistics(arg0) ⇒ CoverageStatistics?

With no argument answers the {line:, branch:, method:} Hash, and with a criterion symbol that one CoverageStatistics.

Overloads:



18
19
20
21
# File 'lib/simplecov/file_list.rb', line 18

def coverage_statistics(criterion = nil)
  stats = (@coverage_statistics ||= compute_coverage_statistics)
  criterion ? stats[criterion] : stats
end

#coverage_statistics_by_fileHash[criterion, Array[CoverageStatistics]]

Returns:



23
24
25
# File 'lib/simplecov/file_list.rb', line 23

def coverage_statistics_by_file
  @coverage_statistics_by_file ||= compute_coverage_statistics_by_file
end

#covered_branchesInteger?

Returns:

  • (Integer, nil)


73
74
75
# File 'lib/simplecov/file_list.rb', line 73

def covered_branches
  coverage_statistics[:branch]&.covered
end

#covered_linesInteger?

Returns:

  • (Integer, nil)


27
28
29
# File 'lib/simplecov/file_list.rb', line 27

def covered_lines
  coverage_statistics[:line]&.covered
end

#covered_methodsInteger?

Returns:

  • (Integer, nil)


89
90
91
# File 'lib/simplecov/file_list.rb', line 89

def covered_methods
  coverage_statistics[:method]&.covered
end

#covered_percent(criterion = :line) ⇒ Float?

Nil if the criterion was not measured.

Parameters:

  • (criterion)

Returns:

  • (Float, nil)


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

def covered_percent(criterion = :line)
  coverage_statistics(criterion)&.percent
end

#covered_percentagesArray[Float?]

Returns:

  • (Array[Float?])


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

def covered_percentages
  map(&:covered_percent)
end

#covered_strength(criterion = :line) ⇒ Float?

The strength (average hits per relevant unit) for the given criterion.

Parameters:

  • (criterion)

Returns:

  • (Float, nil)


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

def covered_strength(criterion = :line)
  coverage_statistics(criterion)&.strength
end

#eachvoid #eachEnumerator[SourceFile, untyped]

Overloads:

  • #eachvoid

    This method returns an undefined value.

  • #eachEnumerator[SourceFile, untyped]

    Returns:

Yields:

Yield Parameters:

Yield Returns:

  • (void)


751
752
# File 'sig/simplecov.rbs', line 751

def each: () { (SourceFile) -> void } -> void
| () -> Enumerator[SourceFile, untyped]

#empty?Boolean

Returns:

  • (Boolean)


759
# File 'sig/simplecov.rbs', line 759

def empty?: () -> bool

#enabled_criteria_for_reportingArray[criterion]

:line (or its :oneshot_line synonym) is reported when either criterion is enabled; the JRuby-gated branch/method criteria are reported when they pass their own engine-support check.

Returns:

  • (Array[criterion])


127
128
129
130
131
132
133
# File 'lib/simplecov/file_list.rb', line 127

def enabled_criteria_for_reporting
  criteria = [] #: Array[SimpleCov::criterion]
  criteria << :line if SimpleCov.line_coverage?
  criteria << :branch if SimpleCov.branch_coverage?
  criteria << :method if SimpleCov.method_coverage?
  criteria
end

#least_covered_fileString?

Nil for an empty list, such as a fully filtered result.

Returns:

  • (String, nil)


48
49
50
51
52
53
# File 'lib/simplecov/file_list.rb', line 48

def least_covered_file
  # `covered_percent` is nil only for an unmeasured criterion, and :line
  # is always measured, so the `|| 0.0` arm never fires at runtime; it
  # exists to satisfy min_by's Comparable requirement.
  min_by { |file| file.covered_percent || 0.0 }&.filename
end

#lengthInteger

Returns:

  • (Integer)


754
# File 'sig/simplecov.rbs', line 754

def length: () -> Integer

#lines_of_codeInteger?

Returns:

  • (Integer, nil)


55
56
57
# File 'lib/simplecov/file_list.rb', line 55

def lines_of_code
  coverage_statistics[:line]&.total
end

#mapvoid

This method returns an undefined value.



755
# File 'sig/simplecov.rbs', line 755

def map: [U] () { (SourceFile) -> U } -> Array[U]

#method_covered_percentFloat?

Returns:

  • (Float, nil)


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

def method_covered_percent
  coverage_statistics[:method]&.percent
end

#missed_branchesInteger?

Returns:

  • (Integer, nil)


77
78
79
# File 'lib/simplecov/file_list.rb', line 77

def missed_branches
  coverage_statistics[:branch]&.missed
end

#missed_linesInteger?

Returns:

  • (Integer, nil)


31
32
33
# File 'lib/simplecov/file_list.rb', line 31

def missed_lines
  coverage_statistics[:line]&.missed
end

#missed_methodsInteger?

Returns:

  • (Integer, nil)


93
94
95
# File 'lib/simplecov/file_list.rb', line 93

def missed_methods
  coverage_statistics[:method]&.missed
end

#never_linesInteger

Returns:

  • (Integer)


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

def never_lines
  sum { |f| f.never_lines.size }
end

#sizeInteger

Returns:

  • (Integer)


753
# File 'sig/simplecov.rbs', line 753

def size: () -> Integer

#skipped_linesInteger

Returns:

  • (Integer)


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

def skipped_lines
  sum { |f| f.skipped_lines.size }
end

#to_aArray[SourceFile]

Returns:



760
# File 'sig/simplecov.rbs', line 760

def to_a: () -> Array[SourceFile]

#to_aryArray[SourceFile]

Returns:



761
# File 'sig/simplecov.rbs', line 761

def to_ary: () -> Array[SourceFile]

#total_branchesInteger?

Returns:

  • (Integer, nil)


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

def total_branches
  coverage_statistics[:branch]&.total
end

#total_methodsInteger?

Returns:

  • (Integer, nil)


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

def total_methods
  coverage_statistics[:method]&.total
end