Class: Textus::Manifest::Policies

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/manifest/policies.rb

Defined Under Namespace

Classes: Block, PolicySet

Constant Summary collapse

EMPTY_SET =
PolicySet.new(refresh: nil, handler_allowlist: nil, promote: nil, retention: nil)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blocks) ⇒ Policies

Returns a new instance of Policies.



11
12
13
# File 'lib/textus/manifest/policies.rb', line 11

def initialize(blocks)
  @blocks = blocks
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



15
16
17
# File 'lib/textus/manifest/policies.rb', line 15

def blocks
  @blocks
end

Class Method Details

.parse(raw) ⇒ Object



7
8
9
# File 'lib/textus/manifest/policies.rb', line 7

def self.parse(raw)
  new(Array(raw).map { |b| Block.new(b) })
end

Instance Method Details

#explain(key) ⇒ Object



32
33
34
# File 'lib/textus/manifest/policies.rb', line 32

def explain(key)
  @blocks.select { |b| Textus::Domain::Policy::Matcher.matches?(b.match, key) }
end

#for(key) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/textus/manifest/policies.rb', line 17

def for(key)
  slots = { refresh: [], handler_allowlist: [], promote: [], retention: [] }
  @blocks.each do |b|
    next unless Textus::Domain::Policy::Matcher.matches?(b.match, key)

    slots.each_key { |slot| slots[slot] << b if b.public_send(slot) }
  end
  PolicySet.new(
    refresh: pick(slots[:refresh], :refresh, key),
    handler_allowlist: pick(slots[:handler_allowlist], :handler_allowlist, key),
    promote: pick(slots[:promote], :promote, key),
    retention: pick(slots[:retention], :retention, key),
  )
end