File: combine.rb

package info (click to toggle)
ruby-simplecov 0.22.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,512 kB
  • sloc: ruby: 5,550; makefile: 10
file content (30 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module SimpleCov
  # Functionally for combining coverage results
  #
  module Combine
  module_function

    #
    # Combine two coverage based on the given combiner_module.
    #
    # Combiners should always be called through this interface,
    # as it takes care of short-circuiting of one of the coverages is nil.
    #
    # @return [Hash]
    def combine(combiner_module, coverage_a, coverage_b)
      return existing_coverage(coverage_a, coverage_b) if empty_coverage?(coverage_a, coverage_b)

      combiner_module.combine(coverage_a, coverage_b)
    end

    def empty_coverage?(coverage_a, coverage_b)
      !(coverage_a && coverage_b)
    end

    def existing_coverage(coverage_a, coverage_b)
      coverage_a || coverage_b
    end
  end
end