Class: ActiveMutator::AcceptedLedger

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

Overview

Committed, repo-root ledger of accepted (equivalent) survivors. Deliberately NOT inside .active_mutator/ — that dir is gitignored and disposable, while acceptance decisions are durable team/CI state.

Constant Summary collapse

FILENAME =
".active_mutator_accepted.json"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, entries) ⇒ AcceptedLedger

Returns a new instance of AcceptedLedger.



24
25
26
27
# File 'lib/active_mutator/accepted_ledger.rb', line 24

def initialize(path, entries)
  @path = path
  @entries = entries
end

Class Method Details

.from_hash(hash) ⇒ Object



17
18
19
20
21
22
# File 'lib/active_mutator/accepted_ledger.rb', line 17

def self.from_hash(hash)
  Fingerprint.new(file: hash.fetch("file"), subject: hash.fetch("subject"),
                  description: hash.fetch("description"),
                  original_snippet: hash.fetch("original_snippet"),
                  ordinal: hash.fetch("ordinal"))
end

.load(root) ⇒ Object



11
12
13
14
15
# File 'lib/active_mutator/accepted_ledger.rb', line 11

def self.load(root)
  path = File.join(root, FILENAME)
  entries = File.exist?(path) ? JSON.parse(File.read(path)) : []
  new(path, entries.map { |e| from_hash(e) })
end

Instance Method Details

#accept!(new_fingerprints, all_current_fingerprints) ⇒ Object

Union new acceptances in, prune anything no longer matching a current mutant, write atomically.



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

def accept!(new_fingerprints, all_current_fingerprints)
  current = all_current_fingerprints.to_set
  @entries = (@entries + new_fingerprints).uniq.select { |e| current.include?(e) }
  AtomicFile.write(@path, JSON.pretty_generate(@entries.map(&:to_h)))
  nil
end

#accepted?(fingerprint) ⇒ Boolean

Returns:

  • (Boolean)


29
# File 'lib/active_mutator/accepted_ledger.rb', line 29

def accepted?(fingerprint) = @entries.include?(fingerprint)

#stale_entries(all_current_fingerprints) ⇒ Object



31
32
33
34
# File 'lib/active_mutator/accepted_ledger.rb', line 31

def stale_entries(all_current_fingerprints)
  current = all_current_fingerprints.to_set
  @entries.reject { |e| current.include?(e) }
end