Module: SimpleCov::Result::Serialization

Included in:
SimpleCov::Result
Defined in:
lib/simplecov/result/serialization.rb,
sig/simplecov.rbs

Instance Method Summary collapse

Instance Method Details

#append_contexts(data) ⇒ void

This method returns an undefined value.

Serialized whenever a map was recorded, even an empty one: for the merge, the key's presence is the signal that this result tracked tests, which is what lets it tell "tracked and covered nothing" from "never tracked". The map's files are restricted to this result's post-filter universe.

Parameters:

  • data (Hash[String, untyped])


21
22
23
24
25
26
# File 'lib/simplecov/result/serialization.rb', line 21

def append_contexts(data)
  map = contexts
  return unless map

  data["contexts"] = map.to_h(only: context_filenames)
end

#context_filenamesSet[String]

Returns:

  • (Set[String])


28
29
30
# File 'lib/simplecov/result/serialization.rb', line 28

def context_filenames
  Set.new(filenames)
end

#coverageHash[String, untyped]

A live result's criterion keys are Symbols while entries parsed back from .resultset.json carry Strings, and the combiners read only String keys. Serializing with String keys is what lets a live result merged against a stored entry contribute its counts instead of being dropped.

Returns:

  • (Hash[String, untyped])


36
37
38
39
40
# File 'lib/simplecov/result/serialization.rb', line 36

def coverage
  original_result.slice(*filenames).transform_values do |file_coverage|
    file_coverage.transform_keys(&:to_s)
  end
end

#to_hashHash[String, Hash[String, untyped]]

Returns:

  • (Hash[String, Hash[String, untyped]])


6
7
8
9
10
11
12
13
# File 'lib/simplecov/result/serialization.rb', line 6

def to_hash
  data = {"coverage" => coverage, "timestamp" => created_at.to_f} #: Hash[String, untyped]
  data["run_id"] = run_id if run_id
  data["worker_id"] = worker_id if worker_id
  data["tracked_files"] = tracked_files unless tracked_files.empty?
  append_contexts(data)
  {command_name => data}
end