Class: CircuitBreaker::WorkflowBuilder::DSL::ActionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/circuit_breaker/workflow_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow_builder) ⇒ ActionBuilder

Returns a new instance of ActionBuilder.



54
55
56
57
58
# File 'lib/circuit_breaker/workflow_dsl.rb', line 54

def initialize(workflow_builder)
  @workflow_builder = workflow_builder
  @context = ActionContext.new
  @actions = []
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



52
53
54
# File 'lib/circuit_breaker/workflow_dsl.rb', line 52

def actions
  @actions
end

#contextObject (readonly)

Returns the value of attribute context.



52
53
54
# File 'lib/circuit_breaker/workflow_dsl.rb', line 52

def context
  @context
end

Instance Method Details

#execute(executor, method, result_name = nil, **params) ⇒ Object



60
61
62
# File 'lib/circuit_breaker/workflow_dsl.rb', line 60

def execute(executor, method, result_name = nil, **params)
  @actions << [executor, method, result_name, params]
end

#execute_actions(token) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/circuit_breaker/workflow_dsl.rb', line 64

def execute_actions(token)
  puts "Executing actions for token #{token.id}..."
  @actions.each do |executor, method, result_name, params|
    puts "  Executing #{method} -> #{result_name}"
    result = executor.send(method, token, **params)
    puts "  Result: #{result.inspect}"
    @context.add_result(result_name, result) if result_name
  end
end