Class: Textus::Application::Read::PolicyExplain::Impl

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/application/read/policy_explain.rb

Instance Method Summary collapse

Constructor Details

#initialize(caps:) ⇒ Impl

Returns a new instance of Impl.



12
13
14
# File 'lib/textus/application/read/policy_explain.rb', line 12

def initialize(caps:)
  @manifest = caps.manifest
end

Instance Method Details

#call(key:) ⇒ Object



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
# File 'lib/textus/application/read/policy_explain.rb', line 16

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?,
      }
    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 },
    },
  }
end