Class: Evilution::Coverage::MapStore Private
- Inherits:
-
Object
- Object
- Evilution::Coverage::MapStore
- Defined in:
- lib/evilution/coverage/map_store.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Disk cache for a per-example coverage Map under .evilution/coverage/, keyed by a per-file content digest so a map survives across runs and invalidates one file at a time.
load is partial: it returns a Map pruned to the files whose on-disk content
still matches the cached digest. A stale or deleted file is dropped (so its
built? is false and the caller falls back to lexical targeting) while every
fresh file stays queryable. A missing or corrupt cache returns nil, signalling
the caller to rebuild from scratch.
Constant Summary collapse
- DEFAULT_ROOT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
".evilution/coverage"- CACHE_FILE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"map.json"
Instance Method Summary collapse
-
#initialize(root: DEFAULT_ROOT, digest: Evilution::Coverage::Digest.new) ⇒ MapStore
constructor
private
A new instance of MapStore.
- #load(source_files) ⇒ Object private
- #save(map, source_files) ⇒ Object private
-
#stale_files(source_files) ⇒ Object
private
Source files whose on-disk content no longer matches the cache (changed, deleted, or never cached) -- the caller rebuilds these.
Constructor Details
#initialize(root: DEFAULT_ROOT, digest: Evilution::Coverage::Digest.new) ⇒ MapStore
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MapStore.
22 23 24 25 |
# File 'lib/evilution/coverage/map_store.rb', line 22 def initialize(root: DEFAULT_ROOT, digest: Evilution::Coverage::Digest.new) @root = root @digest = digest end |
Instance Method Details
#load(source_files) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 38 39 40 |
# File 'lib/evilution/coverage/map_store.rb', line 33 def load(source_files) payload = read_payload return nil unless payload cached_digests = payload["digests"] || {} fresh = source_files.select { |file| fresh?(file, cached_digests) } pruned_map(payload["map"] || {}, fresh) end |
#save(map, source_files) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 |
# File 'lib/evilution/coverage/map_store.rb', line 27 def save(map, source_files) payload = { "digests" => digests_for(source_files), "map" => map.to_h } FileUtils.mkdir_p(@root) File.write(cache_path, JSON.generate(payload)) end |
#stale_files(source_files) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Source files whose on-disk content no longer matches the cache (changed, deleted, or never cached) -- the caller rebuilds these. Every file is stale when there is no cache at all.
45 46 47 48 49 50 51 |
# File 'lib/evilution/coverage/map_store.rb', line 45 def stale_files(source_files) payload = read_payload return source_files.dup unless payload cached_digests = payload["digests"] || {} source_files.reject { |file| fresh?(file, cached_digests) } end |