Class: Textus::Read::Freshness

Inherits:
Object
  • Object
show all
Extended by:
Contract::DSL
Defined in:
lib/textus/read/freshness.rb

Overview

Per-entry lifecycle report (ADR 0079). Walks every entry declared in the manifest, consults ‘rules.for(key)` for a `lifecycle:` policy, and reports the unified verdict. Status is one of :fresh, :expired, or :no_policy; the row also carries the policy’s :action (on_expire).

Instance Method Summary collapse

Methods included from Contract::DSL

arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view

Constructor Details

#initialize(container:, call:) ⇒ Freshness

Returns a new instance of Freshness.



20
21
22
23
24
25
# File 'lib/textus/read/freshness.rb', line 20

def initialize(container:, call:)
  @container  = container
  @call       = call
  @manifest   = container.manifest
  @file_store = container.file_store
end

Instance Method Details

#call(prefix: nil, zone: nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/textus/read/freshness.rb', line 39

def call(prefix: nil, zone: nil)
  rows = []
  @manifest.data.entries.each do |mentry|
    next if prefix && !mentry.key.start_with?(prefix)
    next if zone && mentry.zone != zone

    rows << row_for(mentry)
  end
  rows
end

#soonest_due(prefix: nil, zone: nil) ⇒ Object

Returns the soonest ‘next_due_at` across all entries with a fetch policy, as an ISO-8601 string, or nil if none.



29
30
31
32
33
34
35
36
37
# File 'lib/textus/read/freshness.rb', line 29

def soonest_due(prefix: nil, zone: nil)
  times = call(prefix: prefix, zone: zone)
          .map { |r| r[:next_due_at] }
          .compact
          .map { |t| Time.parse(t) }
  return nil if times.empty?

  times.min.utc.iso8601
end