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.



22
23
24
25
# File 'lib/simplecov/source_file/skip_chunks.rb', line 22

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

Class Attribute Details

.nocov_warnedObject (readonly)

Returns the value of attribute nocov_warned.



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

def nocov_warned
  @nocov_warned
end

Instance Method Details

#directive_chunksObject



44
45
46
# File 'lib/simplecov/source_file/skip_chunks.rb', line 44

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

#for(criterion) ⇒ Object

‘:method` ignores nocov chunks (Ruby’s Coverage doesn’t tie method entries to line ranges); ‘:line` / `:branch` honor both the nocov chunks and the per-criterion directive ranges.



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

def for(criterion)
  if criterion == :method
    directive_chunks.fetch(:method)
  else
    nocov_chunks + directive_chunks.fetch(criterion)
  end
end

#nocov_chunksObject

no_cov_chunks is zero indexed to work directly with the array holding the lines.



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

def nocov_chunks
  @nocov_chunks ||= build_nocov_chunks
end