Class: ApprovalEngine::IterationBuilder
- Inherits:
-
Object
- Object
- ApprovalEngine::IterationBuilder
- Defined in:
- app/services/approval_engine/iteration_builder.rb
Overview
Implements the append-only iteration cycle. Rather than resetting an approved step back to pending (which would destroy the audit trail), requesting changes clones the track’s current iteration into a fresh one, so every past attempt remains permanently on the ledger.
Always invoked while the approval is locked, so it does not lock again.
Class Method Summary collapse
Instance Method Summary collapse
- #build! ⇒ Object
-
#initialize(from_step) ⇒ IterationBuilder
constructor
A new instance of IterationBuilder.
Constructor Details
#initialize(from_step) ⇒ IterationBuilder
Returns a new instance of IterationBuilder.
13 14 15 16 |
# File 'app/services/approval_engine/iteration_builder.rb', line 13 def initialize(from_step) @from_step = from_step @track = from_step.track end |
Class Method Details
.build_next_iteration!(from_step) ⇒ Object
9 10 11 |
# File 'app/services/approval_engine/iteration_builder.rb', line 9 def self.build_next_iteration!(from_step) new(from_step).build! end |
Instance Method Details
#build! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/approval_engine/iteration_builder.rb', line 18 def build! blueprint = track.steps.for_iteration(from_step.iteration).order(:layer, :created_at).to_a first_layer = blueprint.map(&:layer).min blueprint.each do |old_step| track.steps.create!( tenant_id: old_step.tenant_id, name: old_step.name, layer: old_step.layer, iteration: next_iteration, status: old_step.layer == first_layer ? "pending" : "waiting", approvals_required: old_step.approvals_required, timeout_after: old_step.timeout_after, assigned_actor: old_step.assigned_actor ) end end |