Class: DeepCover::Reporter::Base

Inherits:
Object
  • Object
show all
Includes:
Memoize
Defined in:
lib/deep_cover/reporter/base.rb

Direct Known Subclasses

HTML::Site, Istanbul, Text

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Memoize

#freeze, included

Constructor Details

#initialize(coverage, **options) ⇒ Base

Returns a new instance of Base.



13
14
15
16
# File 'lib/deep_cover/reporter/base.rb', line 13

def initialize(coverage, **options)
  @coverage = coverage
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/deep_cover/reporter/base.rb', line 11

def options
  @options
end

Instance Method Details

#analysisObject



18
19
20
# File 'lib/deep_cover/reporter/base.rb', line 18

def analysis
  @analysis ||= Coverage::Analysis.new(@coverage.covered_codes, **options)
end

#each(&block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/deep_cover/reporter/base.rb', line 22

def each(&block)
  return to_enum :each unless block_given?
  @coverage.each do |covered_code|
    yield relative_path(covered_code.path), covered_code
  end
  self
end

#populate_statsObject

Same as populate, but also yields data, which is either the analysis data (for leaves) of the sum of the children (for subtrees)



32
33
34
35
36
37
38
39
40
41
# File 'lib/deep_cover/reporter/base.rb', line 32

def populate_stats
  return to_enum(__method__) unless block_given?
  Tree::Util.populate_from_map(
      tree: tree,
      map: map,
      merge: ->(child_data) { Tools.merge(*child_data, :+) }
  ) do |full_path, partial_path, data, children|
    yield relative_path(full_path), relative_path(partial_path), data, children
  end
end