Class: ActiveMutator::CoverageMap

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mutator/coverage_map.rb

Overview

Cache format v2: primary data is per-example records (=> [[abs_path, line], ...]); the inverted index is derived in memory at load. A missing/old version is simply stale — the cache is disposable, so there is no migration path, only regeneration.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CoverageMap

Returns a new instance of CoverageMap.



13
14
15
16
17
18
19
# File 'lib/active_mutator/coverage_map.rb', line 13

def initialize(data)
  @version = data["version"]
  @records = data.fetch("records", {})
  @times = data.fetch("times", {})
  @digests = data.fetch("digests", {})
  @map = build_map
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



11
12
13
# File 'lib/active_mutator/coverage_map.rb', line 11

def records
  @records
end

#versionObject (readonly)

Returns the value of attribute version.



11
12
13
# File 'lib/active_mutator/coverage_map.rb', line 11

def version
  @version
end

Class Method Details

.load(path) ⇒ Object



9
# File 'lib/active_mutator/coverage_map.rb', line 9

def self.load(path) = new(JSON.parse(File.read(path)))

Instance Method Details

#examples_covering_file(abs_path) ⇒ Object



33
34
35
36
37
# File 'lib/active_mutator/coverage_map.rb', line 33

def examples_covering_file(abs_path)
  @records.filter_map do |example_id, hits|
    example_id if hits.any? { |(path, _line)| path == abs_path }
  end
end

#examples_for(file, lines) ⇒ Object



21
22
23
# File 'lib/active_mutator/coverage_map.rb', line 21

def examples_for(file, lines)
  lines.flat_map { |line| @map.fetch("#{file}:#{line}", []) }.uniq.sort
end

#examples_for_spec_file(rel_spec_path) ⇒ Object



39
40
41
42
43
# File 'lib/active_mutator/coverage_map.rb', line 39

def examples_for_spec_file(rel_spec_path)
  @records.keys.select do |example_id|
    example_id.sub(%r{\A\./}, "").start_with?("#{rel_spec_path}[")
  end
end

#fresh?(digests) ⇒ Boolean

Returns:

  • (Boolean)


31
# File 'lib/active_mutator/coverage_map.rb', line 31

def fresh?(digests) = @version == 2 && @digests == digests

#time_for(example_ids) ⇒ Object



25
26
27
28
29
# File 'lib/active_mutator/coverage_map.rb', line 25

def time_for(example_ids)
  # `|| 0.0`, not fetch-with-default: a key present with nil value must
  # also coerce to zero, or Runner#plan_work explodes with TypeError.
  example_ids.sum { |id| @times[id] || 0.0 }
end