Class: Textus::Application::Reads::Get

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/application/reads/get.rb

Overview

Pure read: returns the on-disk envelope annotated with a freshness verdict. Never triggers refresh; never invokes the orchestrator.

For interactive reads that want refresh-on-stale, use ‘Reads::GetOrRefresh`, which composes this with the orchestrator.

Instance Method Summary collapse

Constructor Details

#initialize(ctx:, evaluator: Textus::Domain::Freshness::Evaluator) ⇒ Get

Returns a new instance of Get.



10
11
12
13
# File 'lib/textus/application/reads/get.rb', line 10

def initialize(ctx:, evaluator: Textus::Domain::Freshness::Evaluator)
  @ctx       = ctx
  @evaluator = evaluator
end

Instance Method Details

#call(key) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/textus/application/reads/get.rb', line 15

def call(key)
  envelope = @ctx.store.reader.read_raw_envelope(key)
  return nil if envelope.nil?

  policy_set = @ctx.store.manifest.rules_for(key)
  refresh_policy = policy_set.refresh
  return annotate_fresh(envelope) if refresh_policy.nil?

  policy = refresh_policy.to_freshness_policy
  verdict = @evaluator.call(policy, envelope, now: @ctx.now)

  envelope.with(freshness: {
                  "stale" => verdict.stale?,
                  "stale_reason" => verdict.reason,
                  "refreshing" => false,
                })
end