Class: Textus::Domain::Freshness::Evaluator
- Inherits:
-
Object
- Object
- Textus::Domain::Freshness::Evaluator
- Defined in:
- lib/textus/domain/freshness/evaluator.rb
Overview
The single currency evaluator (ADR 0099). Answers “is the stored data stale relative to its source?” for every produce-method:
- intake (source.from: handler) -> AGE signal: now - basis > source.ttl,
basis = _meta.last_fetched_at (else file mtime). No ttl -> :no_policy
(skipped — a cadence-less handler is not auto-re-pulled).
- derived/external -> DRIFT signal: a source changed since generated.at
(surfaced by the doctor generator_drift check; derived entries annotate
fresh at read time because reconcile converges them reactively).
Replaces Domain::IntakeStaleness and Domain::Staleness::GeneratorCheck and the inline copies in Read::Get / Read::Freshness.
Instance Method Summary collapse
-
#drift_rows(mentry) ⇒ Object
Generator-drift rows for one entry (replaces Staleness::GeneratorCheck# rows_for) — consumed by the doctor generator_drift check.
-
#initialize(manifest:, file_stat:, clock:) ⇒ Evaluator
constructor
A new instance of Evaluator.
-
#intake_basis(mentry) ⇒ Object
Age basis as a Time (or nil): _meta.last_fetched_at when present, else file mtime.
-
#stale_intake_keys(prefix: nil, zone: nil) ⇒ Object
Keys of intake entries past their source.ttl — the reconcile produce scope (replaces Domain::IntakeStaleness#call).
-
#verdict(mentry) ⇒ Object
Per-entry currency Verdict (drives Read::Get’s annotation).
Constructor Details
#initialize(manifest:, file_stat:, clock:) ⇒ Evaluator
Returns a new instance of Evaluator.
17 18 19 20 21 |
# File 'lib/textus/domain/freshness/evaluator.rb', line 17 def initialize(manifest:, file_stat:, clock:) @manifest = manifest @file_stat = file_stat @clock = clock end |
Instance Method Details
#drift_rows(mentry) ⇒ Object
Generator-drift rows for one entry (replaces Staleness::GeneratorCheck# rows_for) — consumed by the doctor generator_drift check.
53 54 55 56 57 58 59 |
# File 'lib/textus/domain/freshness/evaluator.rb', line 53 def drift_rows(mentry) return [] unless drift_applicable?(mentry) path = Textus::Key::Path.resolve(@manifest.data, mentry) reason = drift_reason(mentry, path) reason ? [drift_row(mentry, path, reason)] : [] end |
#intake_basis(mentry) ⇒ Object
Age basis as a Time (or nil): _meta.last_fetched_at when present, else file mtime. The single definition the three call sites used to repeat.
44 45 46 47 48 49 |
# File 'lib/textus/domain/freshness/evaluator.rb', line 44 def intake_basis(mentry) path = @manifest.resolver.resolve(mentry.key).path return nil unless @file_stat.exists?(path) last_fetched_at(mentry, path) || @file_stat.mtime(path) end |
#stale_intake_keys(prefix: nil, zone: nil) ⇒ Object
Keys of intake entries past their source.ttl — the reconcile produce scope (replaces Domain::IntakeStaleness#call). A ttl-less intake entry is :no_policy and skipped; a never-recorded one (with a ttl) is stale.
38 39 40 |
# File 'lib/textus/domain/freshness/evaluator.rb', line 38 def stale_intake_keys(prefix: nil, zone: nil) @manifest.data.entries.select { |m| due?(m, prefix: prefix, zone: zone) }.map(&:key) end |
#verdict(mentry) ⇒ Object
Per-entry currency Verdict (drives Read::Get’s annotation). Non-intake entries are always fresh (retention is GC, not content currency).
25 26 27 28 29 30 31 32 33 |
# File 'lib/textus/domain/freshness/evaluator.rb', line 25 def verdict(mentry) return fresh unless mentry.intake? ttl = mentry.source.ttl_seconds return fresh if ttl.nil? stale = age_stale?(intake_basis(mentry), ttl) Verdict.build(stale: stale, reason: stale ? "ttl exceeded" : nil, fetching: false) end |