Class: Henitai::MutantHistoryStore
- Inherits:
-
Object
- Object
- Henitai::MutantHistoryStore
- Defined in:
- lib/henitai/mutant_history_store.rb
Overview
Persists mutant outcomes across runs in a lightweight SQLite database. rubocop:disable Metrics/ClassLength
Constant Summary collapse
- RUNS_TABLE_SQL =
<<~SQL CREATE TABLE IF NOT EXISTS runs ( id INTEGER PRIMARY KEY AUTOINCREMENT, version TEXT NOT NULL, recorded_at TEXT NOT NULL, mutation_score REAL, mutation_score_indicator REAL, equivalence_uncertainty TEXT, total_mutants INTEGER NOT NULL, killed_mutants INTEGER NOT NULL, survived_mutants INTEGER NOT NULL, timeout_mutants INTEGER NOT NULL, equivalent_mutants INTEGER NOT NULL ); SQL
- MUTANTS_TABLE_SQL =
<<~SQL CREATE TABLE IF NOT EXISTS mutants ( mutant_id TEXT PRIMARY KEY, first_seen_version TEXT NOT NULL, first_seen_at TEXT NOT NULL, last_seen_version TEXT NOT NULL, last_seen_at TEXT NOT NULL, current_status TEXT NOT NULL, status_history TEXT NOT NULL, days_alive INTEGER NOT NULL ); SQL
- INSERT_RUN_SQL =
<<~SQL INSERT INTO runs ( version, recorded_at, mutation_score, mutation_score_indicator, equivalence_uncertainty, total_mutants, killed_mutants, survived_mutants, timeout_mutants, equivalent_mutants ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) SQL
- UPSERT_MUTANT_SQL =
<<~SQL INSERT INTO mutants ( mutant_id, first_seen_version, first_seen_at, last_seen_version, last_seen_at, current_status, status_history, days_alive ) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(mutant_id) DO UPDATE SET last_seen_version = excluded.last_seen_version, last_seen_at = excluded.last_seen_at, current_status = excluded.current_status, status_history = excluded.status_history, days_alive = excluded.days_alive SQL
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path:) ⇒ MutantHistoryStore
constructor
A new instance of MutantHistoryStore.
- #record(result, version:, recorded_at: Time.now.utc) ⇒ Object
- #trend_report ⇒ Object
Constructor Details
#initialize(path:) ⇒ MutantHistoryStore
Returns a new instance of MutantHistoryStore.
78 79 80 |
# File 'lib/henitai/mutant_history_store.rb', line 78 def initialize(path:) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
82 83 84 |
# File 'lib/henitai/mutant_history_store.rb', line 82 def path @path end |
Instance Method Details
#record(result, version:, recorded_at: Time.now.utc) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/henitai/mutant_history_store.rb', line 84 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) Array(result.mutants).each do |mutant| upsert_mutant(db, mutant, version, recorded_at) end end end end |
#trend_report ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/henitai/mutant_history_store.rb', line 98 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 |