Class: Pm::Process

Inherits:
Object
  • Object
show all
Includes:
ExtendableByTag
Defined in:
lib/flow.rb

Overview

Basic process

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExtendableByTag

#extend_by_tag

Constructor Details

#initialize(config, context) ⇒ Process



42
43
44
45
46
47
48
# File 'lib/flow.rb', line 42

def initialize(config, context)
  @config = config
  @context = context
  @operations = []

  extend_by_tag
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



40
41
42
# File 'lib/flow.rb', line 40

def config
  @config
end

#contextObject (readonly)

Returns the value of attribute context.



40
41
42
# File 'lib/flow.rb', line 40

def context
  @context
end

Instance Method Details

#build_next_operations(old_operation) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/flow.rb', line 71

def build_next_operations(old_operation)
  old_operation.config[old_operation.status].each do |operation_conf|
    operation_conf.each do |tag, _value|
      new_config = config['operations'].find { |o| o['tag'] == tag }
      new_operations = Operation.new(new_config, old_operation.context)
      @operations << new_operations
    end
  end
end

#run_iterationObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/flow.rb', line 58

def run_iteration
  next_operations = @operations.select(&:ready?)
  next_operations.map(&:complete)

  next_operations.map do |old_operation|
    next if old_operation.config[old_operation.status].nil?

    build_next_operations(old_operation)
  end

  run_iteration if @operations.any?(&:ready?)
end

#startObject



50
51
52
53
54
55
56
# File 'lib/flow.rb', line 50

def start
  @operations = config['start'].map do |tag|
    new_config = config['operations'].find { |o| o['tag'] == tag }
    Operation.new(new_config, context)
  end
  run_iteration
end