Class: Textus::Application::Policy::Promotion
- Inherits:
-
Object
- Object
- Textus::Application::Policy::Promotion
- Defined in:
- lib/textus/application/policy/promotion.rb
Overview
Promotion evaluates a list of named predicates against a pending-proposal entry and returns a Result indicating whether all requirements are met.
Lives in Application because the predicates it wires up read live state from explicit ports (schemas, manifest, role). The Domain-side rule statement (“this policy requires predicates X and Y”) is captured by Textus::Domain::Policy::Promote.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- REGISTRY =
{ "schema_valid" => -> { Predicates::SchemaValid.new }, "human_accept" => -> { Predicates::HumanAccept.new }, }.freeze
Instance Attribute Summary collapse
-
#predicates ⇒ Object
readonly
Returns the value of attribute predicates.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(entry:, schemas:, manifest:, role:) ⇒ Object
-
#initialize(predicates:) ⇒ Promotion
constructor
A new instance of Promotion.
- #predicate_names ⇒ Object
Constructor Details
#initialize(predicates:) ⇒ Promotion
Returns a new instance of Promotion.
31 32 33 |
# File 'lib/textus/application/policy/promotion.rb', line 31 def initialize(predicates:) @predicates = predicates end |
Instance Attribute Details
#predicates ⇒ Object (readonly)
Returns the value of attribute predicates.
29 30 31 |
# File 'lib/textus/application/policy/promotion.rb', line 29 def predicates @predicates end |
Class Method Details
.from_names(names) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/textus/application/policy/promotion.rb', line 19 def self.from_names(names) predicates = Array(names).map do |n| ctor = REGISTRY[n.to_s] or raise Textus::UsageError.new( "unknown promotion predicate: '#{n}' (known: #{REGISTRY.keys.join(", ")})", ) ctor.call end new(predicates: predicates) end |
Instance Method Details
#evaluate(entry:, schemas:, manifest:, role:) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/textus/application/policy/promotion.rb', line 39 def evaluate(entry:, schemas:, manifest:, role:) reasons = [] @predicates.each do |pred| ok = invoke(pred, entry: entry, schemas: schemas, manifest: manifest, role: role) reasons << "#{pred.name}: #{pred.reason || "predicate failed"}" unless ok end Result.new(ok?: reasons.empty?, reasons: reasons) end |
#predicate_names ⇒ Object
35 36 37 |
# File 'lib/textus/application/policy/promotion.rb', line 35 def predicate_names @predicates.map(&:name) end |