Class: Textus::Read::Freshness

Inherits:
Object
  • Object
show all
Extended by:
Contract::DSL
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 fetch rule, and reports the current status. Status is one of :fresh, :stale, :never_fetched, or :no_policy.

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:, evaluator: Textus::Domain::Freshness::Evaluator) ⇒ Freshness

Returns a new instance of Freshness.



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

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



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

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.



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

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