Class: Textus::Application::Reads::Get
- Inherits:
-
Object
- Object
- Textus::Application::Reads::Get
- Defined in:
- lib/textus/application/reads/get.rb
Instance Method Summary collapse
- #call(key) ⇒ Object
-
#initialize(ctx:, orchestrator:, evaluator: Textus::Domain::Freshness::Evaluator) ⇒ Get
constructor
A new instance of Get.
Constructor Details
#initialize(ctx:, orchestrator:, evaluator: Textus::Domain::Freshness::Evaluator) ⇒ Get
Returns a new instance of Get.
5 6 7 8 9 |
# File 'lib/textus/application/reads/get.rb', line 5 def initialize(ctx:, orchestrator:, evaluator: Textus::Domain::Freshness::Evaluator) @ctx = ctx @orchestrator = orchestrator @evaluator = evaluator end |
Instance Method Details
#call(key) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/textus/application/reads/get.rb', line 11 def call(key) envelope = @ctx.store.reader.read_raw_envelope(key) return nil if envelope.nil? policy_set = @ctx.store.manifest.policies_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) return annotate(envelope, verdict, refreshing: false) if verdict.fresh? action = policy.decide(verdict) outcome = @orchestrator.execute(action, key: key) case outcome when Textus::Domain::Outcome::Skipped annotate(envelope, verdict, refreshing: false) when Textus::Domain::Outcome::Refreshed fresh_verdict = @evaluator.call(policy, outcome.envelope, now: @ctx.now) annotate(outcome.envelope, fresh_verdict, refreshing: false) when Textus::Domain::Outcome::Detached annotate(envelope, verdict, refreshing: true) when Textus::Domain::Outcome::Failed annotate(envelope, verdict, refreshing: false, refresh_error: outcome.error.) end end |