Class: Textus::Read::Freshness

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/read/freshness.rb

Overview

Per-entry freshness report. Walks every entry declared in the manifest, consults ‘rules_for(key)` for a refresh rule, and reports the current status. Status is one of :fresh, :stale, :never_refreshed, or :no_policy.

Instance Method Summary collapse

Constructor Details

#initialize(container:, call:, evaluator: Textus::Domain::Freshness::Evaluator) ⇒ Freshness

Returns a new instance of Freshness.



10
11
12
13
14
15
16
17
# File 'lib/textus/read/freshness.rb', line 10

def initialize(container:, call:, evaluator: Textus::Domain::Freshness::Evaluator)
  @container  = container
  @call       = call
  @manifest   = container.manifest
  @file_store = container.file_store
  @evaluator  = evaluator
  @cache      = {}
end

Instance Method Details

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



31
32
33
34
35
36
37
38
39
40
# File 'lib/textus/read/freshness.rb', line 31

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 refresh policy, as an ISO-8601 string, or nil if none.



21
22
23
24
25
26
27
28
29
# File 'lib/textus/read/freshness.rb', line 21

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