Class: SimpleCov::SourceFile::SkipChunks

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/source_file/skip_chunks.rb

Overview

Computes the set of line ranges that should be excluded from a SourceFile's coverage for each criterion. Two sources contribute:

  • The deprecated # :nocov: block toggle (lines wrapped between even-numbered pairs of nocov markers are excluded from line and branch coverage).
  • # simplecov:disable / # simplecov:enable block directives, which can be scoped per-criterion (# simplecov:disable branch, etc.) — see SimpleCov::Directive.

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, src) ⇒ SkipChunks

Returns a new instance of SkipChunks.



20
21
22
23
# File 'lib/simplecov/source_file/skip_chunks.rb', line 20

def initialize(filename, src)
  @filename = filename
  @src = src
end

Class Attribute Details

.nocov_warnedObject (readonly)

Returns the value of attribute nocov_warned.



17
18
19
# File 'lib/simplecov/source_file/skip_chunks.rb', line 17

def nocov_warned
  @nocov_warned
end

Instance Method Details

#directive_chunksObject



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

def directive_chunks
  @directive_chunks ||= Directive.disabled_ranges(@src)
end

#for(criterion) ⇒ Object

Every criterion honors the deprecated all-criteria # :nocov: chunks plus its own per-criterion directive ranges. Methods included: they carry a source range, and nocov has always meant "exclude everything here".



29
30
31
# File 'lib/simplecov/source_file/skip_chunks.rb', line 29

def for(criterion)
  nocov_chunks + directive_chunks.fetch(criterion)
end

#nocov_chunksObject

Ranges of 1-based line numbers (see with_index(1) below); consumers subtract 1 to index into the zero-based lines array.



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

def nocov_chunks
  @nocov_chunks ||= build_nocov_chunks
end