Class: Textus::Read::Get

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/read/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 ‘Read::GetOrRefresh`, which composes this with the orchestrator.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Get.



9
10
11
12
13
14
15
# File 'lib/textus/read/get.rb', line 9

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

Instance Method Details

#call(key) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/textus/read/get.rb', line 17

def call(key)
  envelope = read_raw_envelope(key)
  return nil if envelope.nil?

  policy_set = @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: @call.now)

  envelope.with(freshness: Textus::Domain::Freshness.build(
    stale: verdict.stale?,
    reason: verdict.reason,
    refreshing: false,
  ))
end

#get(key) ⇒ Object

Strict variant: raises UnknownKey when the entry is missing. Used by consumers (e.g. Validator) that need to distinguish absence from emptiness.



38
39
40
# File 'lib/textus/read/get.rb', line 38

def get(key)
  call(key) || raise(UnknownKey.new(key, suggestions: @manifest.resolver.suggestions_for(key)))
end