Class: Textus::Read::Get
- Inherits:
-
Object
- Object
- Textus::Read::Get
- Extended by:
- Contract::DSL
- Defined in:
- lib/textus/read/get.rb
Overview
The one read path. ‘fetch:` controls behavior:
fetch: false (default) — pure read: the on-disk envelope annotated with
a lifecycle freshness verdict. NEVER builds the orchestrator and NEVER
mutates. Safe for direct callers (accept/reject/publish, materializer,
uid, validators, hooks).
fetch: true — read-through: after a stale verdict on a `refresh` policy,
hands off to the fetch orchestrator. A read NEVER performs a
destructive action (drop/archive) — those belong to the `tend` sweep
(ADR 0079).
Lifecycle policy comes from the unified ‘lifecycle:` rule slot (ADR 0079).
Instance Method Summary collapse
- #call(key, fetch: false) ⇒ Object
-
#get(key, fetch: false) ⇒ Object
Strict variant: raises UnknownKey when the entry is missing.
-
#initialize(container:, call:, orchestrator: nil, file_stat: Textus::Ports::Storage::FileStat.new) ⇒ Get
constructor
A new instance of Get.
Methods included from Contract::DSL
arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view
Constructor Details
#initialize(container:, call:, orchestrator: nil, file_stat: Textus::Ports::Storage::FileStat.new) ⇒ Get
Returns a new instance of Get.
32 33 34 35 36 37 38 39 |
# File 'lib/textus/read/get.rb', line 32 def initialize(container:, call:, orchestrator: nil, file_stat: Textus::Ports::Storage::FileStat.new) @container = container @call = call @manifest = container.manifest @file_store = container.file_store @file_stat = file_stat @orchestrator = orchestrator # nil → built lazily on first fetch only end |
Instance Method Details
#call(key, fetch: false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/textus/read/get.rb', line 41 def call(key, fetch: false) envelope = annotated_envelope(key) return envelope if envelope.nil? return envelope unless fetch && envelope.freshness&.stale policy = lifecycle_for(key) return envelope unless policy&.on_expire == :refresh # only refresh acts on a read verdict = Textus::Domain::Freshness::Verdict.stale(envelope.freshness.reason) outcome = orchestrator.execute(refresh_policy(policy).decide(verdict), key: key) resolve(outcome, envelope) end |
#get(key, fetch: false) ⇒ Object
Strict variant: raises UnknownKey when the entry is missing. Used by consumers (e.g. uid, Validator) that distinguish absence.
56 57 58 59 |
# File 'lib/textus/read/get.rb', line 56 def get(key, fetch: false) call(key, fetch: fetch) || raise(UnknownKey.new(key, suggestions: @manifest.resolver.suggestions_for(key))) end |