Class: Ruflow::Flow

Inherits:
Action show all
Defined in:
lib/ruflow/flow.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Action

change_options, input_type, with_custom_options

Class Attribute Details

.actionsObject

Returns the value of attribute actions.



18
19
20
# File 'lib/ruflow/flow.rb', line 18

def actions
  @actions
end

.start_action_idObject

Returns the value of attribute start_action_id.



18
19
20
# File 'lib/ruflow/flow.rb', line 18

def start_action_id
  @start_action_id
end

Class Method Details

.check_actions!Object

Raises:

  • (NotImplementedError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ruflow/flow.rb', line 23

def check_actions!
  raise NotImplementedError, 'actions must be defined using set_actions({})' if actions.nil?

  raise NotImplementedError, 'start_action_id must be defined using set_start_action_id(Integer)' if start_action_id.nil?

  raise NotImplementedError, 'actions must be a Hash'  if not(actions.is_a?(Hash))

  raise NotImplementedError, 'start_action not found, change the start_action_id' if start_action.nil?

  if (actions_with_error = actions_without_klass).any?
    raise NotImplementedError, "actions id=#{actions_with_error.keys.join(', ')} must have value as a Hash and define a 'klass:' key"
  end

  if (actions_with_error = actions_mismatch_output_input_type).any?
    raise Error::MismatchOutputInputType.new(actions_with_error)
  end
end

.startObject



41
42
43
44
# File 'lib/ruflow/flow.rb', line 41

def start
  check_actions!
  super(nil)
end

.start_actionObject



46
47
48
# File 'lib/ruflow/flow.rb', line 46

def start_action
  actions[start_action_id]
end

Instance Method Details

#start(param) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ruflow/flow.rb', line 4

def start(param)
  action = self.class.start_action
  value  = param

  while action[:output_to]
    output_port, value = action[:klass].start(value)

    action = self.class.actions[action[:output_to][output_port]]
  end

  action[:klass].start(value)
end