Class: Speedflow::Flow

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

Overview

Used to manage the flow of Speedflow

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Flow

Public: Constructor.

config - Default Hahs of config.

Examples

Flow.new({})
# => <Speedflow::Flow>

Returns a Hash of config.



14
15
16
# File 'lib/speedflow/flow.rb', line 14

def initialize(config)
  @config = config
end

Instance Method Details

#flat_argumentsObject

Public: Get flat arguments from flow.

Returns flat Array of arguments.



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

def flat_arguments
  args = []
  @config['flow'].each do |_, steps|
    steps.each do |s|
      (args << s['arguments'].keys).flatten! unless s['arguments'].nil?
    end
  end
  args.uniq
end

#plugin_managerObject

Plugin manager.

Returns an instance of plugin manager.



74
75
76
# File 'lib/speedflow/flow.rb', line 74

def plugin_manager
  @plugin_manager ||= PluginManager.new(@config['plugins'])
end

#transform_arguments(arguments, prev_values, inputs) ⇒ Object

Public: Transform arguments (to add value)

arguments - Hash of arguments. prev_values - Hash of previous values. inputs - Hash of inputs.

Returns Hash of arguments.



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

def transform_arguments(arguments, prev_values, inputs)
  arguments = arguments.replace_values_from_previous(prev_values)
  arguments.each do |arg_name, arg_values|
    arguments[arg_name][:value] = ''
    if inputs.key?(arg_name)
      arguments[arg_name][:value] = inputs[arg_name]
    elsif arg_values.key?('default')
      arguments[arg_name][:value] = arg_values[:default]
    end
  end
  arguments
end

#trigger(trigger, inputs) ⇒ Object

Public: Trigger.

trigger - Trigger name. inputs - Inputs.

Returns nothing.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/speedflow/flow.rb', line 24

def trigger(trigger, inputs)
  unless @config.flow_trigger?(trigger)
    raise FlowTriggerNotFound, "Unable to trigger: #{trigger}"
  end

  output = {}
  @config['flow'][trigger.to_s].each do |step|
    arguments = step['arguments'] || {}
    step['arguments'] = transform_arguments(arguments, output, inputs)
    step['arguments']['_config'] = @config
    output = plugin_manager.call_action_from_step(step)
  end
end