Class: RubyReactor::Step::ComposeStep

Inherits:
Object
  • Object
show all
Includes:
RubyReactor::Step
Defined in:
lib/ruby_reactor/step/compose_step.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RubyReactor::Step

included

Constructor Details

#initialize(composed_reactor_class, argument_mappings = {}) ⇒ ComposeStep

Returns a new instance of ComposeStep.



10
11
12
13
# File 'lib/ruby_reactor/step/compose_step.rb', line 10

def initialize(composed_reactor_class, argument_mappings = {})
  @composed_reactor_class = composed_reactor_class
  @argument_mappings = argument_mappings
end

Instance Attribute Details

#argument_mappingsObject (readonly)

Returns the value of attribute argument_mappings.



8
9
10
# File 'lib/ruby_reactor/step/compose_step.rb', line 8

def argument_mappings
  @argument_mappings
end

#composed_reactor_classObject (readonly)

Returns the value of attribute composed_reactor_class.



8
9
10
# File 'lib/ruby_reactor/step/compose_step.rb', line 8

def composed_reactor_class
  @composed_reactor_class
end

Class Method Details

.compensate(_reason, arguments, context) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ruby_reactor/step/compose_step.rb', line 32

def self.compensate(_reason, arguments, context)
  step_name = context.current_step
  composed_data = context.composed_contexts[step_name]
  return RubyReactor.Success() unless composed_data && composed_data[:context]

  child_context = composed_data[:context]
  executor = RubyReactor::Executor.new(arguments[:composed_reactor_class], {}, child_context)
  executor.undo_all
  executor.save_context

  RubyReactor.Success()
end

.run(arguments, context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby_reactor/step/compose_step.rb', line 15

def self.run(arguments, context)
  step_name = context.current_step
  composed_data = context.composed_contexts[step_name]
  child_context = prepare_child_context(arguments, context, composed_data)

  # Store the child context in composed_contexts BEFORE execution
  store_child_context(context, step_name, child_context)

  # Execute the composed reactor
  result = execute_child_reactor(arguments[:composed_reactor_class], child_context, composed_data)

  # Update the stored context
  store_child_context(context, step_name, child_context)

  handle_execution_result(result)
end

.undo(_result, arguments, context) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruby_reactor/step/compose_step.rb', line 45

def self.undo(_result, arguments, context)
  step_name = context.current_step
  composed_data = context.composed_contexts[step_name]
  return RubyReactor.Success() unless composed_data && composed_data[:context]

  child_context = composed_data[:context]
  executor = RubyReactor::Executor.new(arguments[:composed_reactor_class], {}, child_context)
  executor.undo_all
  executor.save_context

  RubyReactor.Success()
end