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) and the effective guard predicate names for every write transition (ADR 0031).
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
7 8 9 10 |
# File 'lib/textus/read/policy_explain.rb', line 7 def initialize(container:, call: nil) # rubocop:disable Lint/UnusedMethodArgument @manifest = container.manifest @schemas = container.schemas end |
Instance Method Details
#call(key:) ⇒ Object
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 40 41 42 43 |
# File 'lib/textus/read/policy_explain.rb', line 12 def call(key:) matching = @manifest.rules.explain(key) winners = @manifest.rules.for(key) factory = Textus::Domain::Policy::GuardFactory.new(manifest: @manifest, schemas: @schemas) { key: key, matched_blocks: matching.map do |b| { match: b.match, fetch: !b.fetch.nil?, handler_allowlist: !b.handler_allowlist.nil?, guard: !b.guard.nil?, retention: !b.retention.nil?, } end, effective: { fetch: winners.fetch && { ttl_seconds: winners.fetch.ttl_seconds, on_stale: winners.fetch.on_stale, }, handler_allowlist: winners.handler_allowlist&.handlers, retention: winners.retention && { expire_after: winners.retention.expire_after, archive_after: winners.retention.archive_after, }, }, guards: Textus::Domain::Policy::BaseGuards::BASE.keys.to_h do |transition| [transition, factory.for(transition, key).predicates.map(&:name)] end, } end |