Class: Henitai::MutantHistoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/mutant_history_store.rb,
lib/henitai/mutant_history_store/sql.rb

Overview

Persists mutant outcomes across runs in a lightweight SQLite database.

Defined Under Namespace

Modules: Sql

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ MutantHistoryStore

Returns a new instance of MutantHistoryStore.



14
15
16
# File 'lib/henitai/mutant_history_store.rb', line 14

def initialize(path:)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/henitai/mutant_history_store.rb', line 18

def path
  @path
end

Instance Method Details

#record(result, version:, recorded_at: Time.now.utc) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/henitai/mutant_history_store.rb', line 20

def record(result, version:, recorded_at: Time.now.utc)
  FileUtils.mkdir_p(File.dirname(path))

  with_database do |db|
    ensure_schema(db)
    db.transaction do
      insert_run(db, result, version, recorded_at) unless partial_rerun?(result)
      Array(result.mutants).each do |mutant|
        upsert_mutant(db, mutant, version, recorded_at)
      end
    end
  end
end

#trend_reportObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/henitai/mutant_history_store.rb', line 34

def trend_report
  with_database do |db|
    ensure_schema(db)
    {
      generatedAt: Time.now.utc.iso8601,
      runs: load_runs(db),
      mutants: load_mutants(db)
    }
  end
end