Class: Textus::Domain::Policy::GuardFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/domain/policy/guard_factory.rb

Overview

Builds the effective Guard for (transition, key): base floor ++ the predicates declared under rules[].guard. The single place the closed floor and the open ceiling are composed.

Instance Method Summary collapse

Constructor Details

#initialize(manifest:, schemas:, extra: {}) ⇒ GuardFactory

Returns a new instance of GuardFactory.



10
11
12
13
14
# File 'lib/textus/domain/policy/guard_factory.rb', line 10

def initialize(manifest:, schemas:, extra: {})
  @manifest = manifest
  @schemas  = schemas
  @extra    = extra # transient per-call params, e.g. { if_etag: "..." }
end

Instance Method Details

#for(transition, key) ⇒ Object



16
17
18
19
20
# File 'lib/textus/domain/policy/guard_factory.rb', line 16

def for(transition, key)
  specs = BaseGuards.for(transition) + composed(transition, key)
  predicates = specs.map { |spec| build(spec) }.uniq(&:name)
  Guard.new(predicates)
end