Class: Textus::Domain::Policy::Guard
- Inherits:
-
Object
- Object
- Textus::Domain::Policy::Guard
- Defined in:
- lib/textus/domain/policy/guard.rb
Overview
An ordered list of pure predicates over one Evaluation (ADR 0031). check! short-circuits on the first failing predicate that defines a bespoke #error (only zone_writable_by → WriteForbidden, the product’s legible topology refusal); every other failure accumulates into GuardFailed naming the unmet predicate(s).
Instance Attribute Summary collapse
-
#predicates ⇒ Object
readonly
Returns the value of attribute predicates.
Instance Method Summary collapse
- #check!(eval) ⇒ Object
- #explain(eval) ⇒ Object
-
#initialize(predicates) ⇒ Guard
constructor
A new instance of Guard.
Constructor Details
#initialize(predicates) ⇒ Guard
Returns a new instance of Guard.
14 15 16 |
# File 'lib/textus/domain/policy/guard.rb', line 14 def initialize(predicates) @predicates = predicates end |
Instance Attribute Details
#predicates ⇒ Object (readonly)
Returns the value of attribute predicates.
12 13 14 |
# File 'lib/textus/domain/policy/guard.rb', line 12 def predicates @predicates end |
Instance Method Details
#check!(eval) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/textus/domain/policy/guard.rb', line 18 def check!(eval) accumulated = [] @predicates.each do |pred| next if pred.call(eval) raise pred.error(eval) if pred.respond_to?(:error) accumulated << [pred.name, pred.reason] end raise Textus::GuardFailed.new(accumulated) unless accumulated.empty? end |
#explain(eval) ⇒ Object
29 30 31 |
# File 'lib/textus/domain/policy/guard.rb', line 29 def explain(eval) @predicates.map { |p| [p.name, p.call(eval), p.reason] } end |