Class: ApprovalEngine::ApprovalPlan

Inherits:
Object
  • Object
show all
Defined in:
app/models/approval_engine/approval_plan.rb

Overview

A read-only description of what a given event would trigger, produced by ‘RuleEvaluator.preview`. It writes nothing and resolves nothing eagerly — a UX/preview aid, not a contract (rules can change before the real run, so the authoritative routing still happens in `run_approval!`).

Defined Under Namespace

Classes: PlannedStep

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, template:, target:, reason: nil) ⇒ ApprovalPlan

Returns a new instance of ApprovalPlan.



12
13
14
15
16
17
# File 'app/models/approval_engine/approval_plan.rb', line 12

def initialize(status:, template:, target:, reason: nil)
  @status   = status
  @template = template
  @target   = target
  @reason   = reason
end

Instance Attribute Details

#reasonObject (readonly)

Returns the value of attribute reason.



10
11
12
# File 'app/models/approval_engine/approval_plan.rb', line 10

def reason
  @reason
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'app/models/approval_engine/approval_plan.rb', line 10

def status
  @status
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'app/models/approval_engine/approval_plan.rb', line 10

def target
  @target
end

#templateObject (readonly)

Returns the value of attribute template.



10
11
12
# File 'app/models/approval_engine/approval_plan.rb', line 10

def template
  @template
end

Instance Method Details

#actors_for(planned_step) ⇒ Object

Best-effort, read-only resolution of who would be assigned to a planned step. Returns [] if the host resolver is unavailable or raises, so a preview never crashes on a host-side bug.



51
52
53
54
55
56
57
58
# File 'app/models/approval_engine/approval_plan.rb', line 51

def actors_for(planned_step)
  klass = ApprovalEngine.config.actor_class_constant
  return [] unless klass.respond_to?(:resolve_approval_group)

  Array(klass.resolve_approval_group(planned_step.assigned_group, target)).compact
rescue StandardError
  []
end

#error?Boolean

A rule is malformed; the real run would quarantine. ‘reason` says why.

Returns:

  • (Boolean)


30
31
32
# File 'app/models/approval_engine/approval_plan.rb', line 30

def error?
  status == :error
end

#no_approval_required?Boolean

No rule matched — taking the action needs no approval.

Returns:

  • (Boolean)


25
26
27
# File 'app/models/approval_engine/approval_plan.rb', line 25

def no_approval_required?
  status == :no_match
end

#stepsObject

The layers that would be created, in order. Pure template data.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/approval_engine/approval_plan.rb', line 35

def steps
  return [] unless template

  template.template_steps.ordered.map do |tpl_step|
    PlannedStep.new(
      name: tpl_step.name,
      layer: tpl_step.layer,
      assigned_group: tpl_step.assigned_group,
      approvals_required: tpl_step.approvals_required
    )
  end
end

#triggered?Boolean

An approval would be spawned.

Returns:

  • (Boolean)


20
21
22
# File 'app/models/approval_engine/approval_plan.rb', line 20

def triggered?
  status == :match
end