Class: SimpleCov::Combine::CoverageAccumulator::MergedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/combine/coverage_accumulator.rb

Overview

One file's accumulated coverage, against state this object owns outright rather than rebuilt for each merged pair.

Instance Method Summary collapse

Constructor Details

#initialize(coverage, branches:, methods:) ⇒ MergedFile

A criterion is carried for this file when the data carries it, not when this process happens to measure it. A merge runs on behalf of the processes that produced the resultsets and does not necessarily share their configuration: simplecov merge never ran SimpleCov.start at all, and dropping a table it did not ask for would lose branch data the producers did measure. A nil table means nobody measured that criterion; an empty one means it was measured and the file has none.



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/simplecov/combine/coverage_accumulator.rb', line 142

def initialize(coverage, branches:, methods:)
  @branch_coverage = branches
  @method_coverage = methods
  @lines = coverage["lines"]&.dup
  # Branch coverage always reports a table, even an empty one, so
  # `SourceFile` can tell "no branches in this file" from "branch
  # coverage was off". Method coverage stays `nil` until some resultset
  # actually carries methods.
  @branches = BranchesCombiner.absorb({}, coverage["branches"]) if branches || coverage["branches"]
  @methods = MethodsCombiner.absorb(nil, coverage["methods"]) if methods || coverage["methods"]
end

Instance Method Details

#absorb(coverage) ⇒ MergedFile

Folds one more resultset's coverage for this file in.

Returns:



159
160
161
162
163
# File 'lib/simplecov/combine/coverage_accumulator.rb', line 159

def absorb(coverage)
  reconcile_synthesized(coverage)
  @lines = LinesCombiner.merge_into(@lines, coverage["lines"])
  self
end

#to_hObject



165
166
167
168
169
170
# File 'lib/simplecov/combine/coverage_accumulator.rb', line 165

def to_h
  merged = {"lines" => @lines} #: Hash[String, untyped]
  merged["branches"] = BranchesCombiner.materialize(@branches) if @branches
  merged["methods"] = MethodsCombiner.materialize(@methods) if @methods
  merged
end