Class: Textus::Application::Reads::PolicyExplain
- Inherits:
-
Object
- Object
- Textus::Application::Reads::PolicyExplain
- Defined in:
- lib/textus/application/reads/policy_explain.rb
Overview
For one key, surface every matching policy block along with the per-slot effective value (which loses ties win-by-specificity).
Instance Method Summary collapse
- #call(key:) ⇒ Object
-
#initialize(ctx:) ⇒ PolicyExplain
constructor
A new instance of PolicyExplain.
Constructor Details
#initialize(ctx:) ⇒ PolicyExplain
Returns a new instance of PolicyExplain.
7 8 9 |
# File 'lib/textus/application/reads/policy_explain.rb', line 7 def initialize(ctx:) @ctx = ctx 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 |
# File 'lib/textus/application/reads/policy_explain.rb', line 11 def call(key:) policies = @ctx.store.manifest.policies matching = policies.explain(key) winners = policies.for(key) { key: key, matched_blocks: matching.map do |b| { match: b.match, refresh: !b.refresh.nil?, handler_allowlist: !b.handler_allowlist.nil?, promote: !b.promote.nil?, } end, effective: { refresh: winners.refresh && { ttl_seconds: winners.refresh.ttl_seconds, on_stale: winners.refresh.on_stale, }, handler_allowlist: winners.handler_allowlist&.handlers, promote_requires: winners.promote&.requires, }, } end |