Module: Plutonium::Interaction::Concerns::WorkflowDSL

Extended by:
ActiveSupport::Concern
Defined in:
lib/plutonium/interaction/concerns/workflow_dsl.rb

Overview

DO NOT USE

Provides a Domain Specific Language (DSL) for defining workflows in interactions.

This module allows interactions to define a series of steps that can be executed in sequence, with optional conditions for each step.

Examples:

class MyWorkflow < Plutonium::Interaction::Base
  include Plutonium::Interaction::Concerns::WorkflowDSL

  workflow do
    step :validate_input, ValidateInputInteraction
    step :process_data, ProcessDataInteraction, if: ->(ctx) { ctx[:data_valid] }
    step :send_notification, SendNotificationInteraction
  end

  private

  def execute
    execute_workflow(attributes.to_h)
  end
end

Defined Under Namespace

Classes: WorkflowBuilder

Instance Method Summary collapse

Instance Method Details

#execute_workflow(context = {}) ⇒ Plutonium::Interaction::Outcome

Executes the defined workflow.



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/plutonium/interaction/concerns/workflow_dsl.rb', line 68

def execute_workflow(context = {})
  self.class.workflow_steps.reduce(Success.new(context)) do |result, step|
    result.and_then do |ctx|
      if step[:condition].nil? || instance_exec(ctx, &step[:condition])
        step[:use_case].call(context: ctx).map { |outcome| ctx[step[:name]] = outcome }
      else
        Success.new(ctx)
      end
    end
  end
end