Class: Textus::Read::PolicyExplain
- Inherits:
-
Object
- Object
- Textus::Read::PolicyExplain
- Defined in:
- lib/textus/read/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(container:, call: nil) ⇒ PolicyExplain
constructor
rubocop:disable Lint/UnusedMethodArgument.
Constructor Details
#initialize(container:, call: nil) ⇒ PolicyExplain
rubocop:disable Lint/UnusedMethodArgument
6 7 8 |
# File 'lib/textus/read/policy_explain.rb', line 6 def initialize(container:, call: nil) # rubocop:disable Lint/UnusedMethodArgument @manifest = container.manifest end |
Instance Method Details
#call(key:) ⇒ Object
10 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 39 |
# File 'lib/textus/read/policy_explain.rb', line 10 def call(key:) policies = @manifest.rules 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?, retention: !b.retention.nil?, } end, effective: { refresh: winners.refresh && { ttl_seconds: winners.refresh.ttl_seconds, on_stale: winners.refresh.on_stale, }, handler_allowlist: winners.handler_allowlist&.handlers, promotion: winners.promote && { requires: winners.promote.requires }, retention: winners.retention && { expire_after: winners.retention.expire_after, archive_after: winners.retention.archive_after, }, }, } end |