easy_flow 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a271be372fa760d850d21b7c3e90719fe8aef78d378b07c249896fd9f69a6ef4
4
- data.tar.gz: e5e0130c5bc885bd7865e938998a8ebec35549e07c90428764409cce2a4ee2e8
3
+ metadata.gz: 48b43c9ecd7f02841d19f9fd4f10f42ea49092641bd998fb5750d6b61d9d330f
4
+ data.tar.gz: f6b12a0a88c69f17a8aa596dad74c310a936060babb7f76d0f0a7f0f486435fe
5
5
  SHA512:
6
- metadata.gz: dc39e2bb8a0ce09d34d74d2e3c5635c8f7ea70094a7dfc83a4422b7254980e2a6c311c689ada061bd61cb7339d6a1d64e30438daa47c0a0d8f07a710a886fdc0
7
- data.tar.gz: e7160a75079db724308f2dbbcf1d6263730188172b8198d037d9429713350086c87208f8803ede07084c92efb0993a0929988d3a50654411f2c643fc3606c681
6
+ metadata.gz: b8e4a6145d9ba8309fc633274e280d96409978b18f8a8df957add151423d9b75d1365b606efd444ae6a91d9563c27c9a1bfe0355f3e1e946020fb34d03c963d1
7
+ data.tar.gz: 48f5729ef10aa4b053ecf20583c91edbe7cf0f749e4623f85b84733ca6e2663c6e115df0f269a3e987f31d38ff4e4289840b4dc6856785d8611ab194e9d94281
@@ -1,7 +1,10 @@
1
1
  module EasyFlow
2
2
  ChosenFlow = Data.define(:flow_id, :number) do
3
- def self.of(node, registry: EasyFlow.registry)
4
- chosen = (registry.fetch(node.type).flow_chosen_by(node) if registry.registered?(node.type))
3
+ def self.of(node, registry: EasyFlow.registry, run: nil)
4
+ step_type = registry.fetch(node.type) if registry.registered?(node.type)
5
+ return worked_out((run && step_type.flow_chosen_from_run(node, run)) || {}) if step_type&.chooses_flow_from_run?
6
+
7
+ chosen = step_type&.flow_chosen_by(node)
5
8
  return worked_out(chosen) if chosen
6
9
 
7
10
  new(flow_id: node.config["flow"].presence, number: node.config["version"].presence)
@@ -20,7 +20,8 @@ module EasyFlow
20
20
  def start_inner(node)
21
21
  return if @run.inner_runs.exists?(parent_step: node.id)
22
22
 
23
- chosen = ChosenFlow.of(node)
23
+ chosen = ChosenFlow.of(node, run: @run)
24
+ raise InnerFlowError, "The step #{node.id} chose no flow to run" if chosen.flow.nil? && EasyFlow.registry.fetch(node.type).chooses_flow_from_run?
24
25
  raise InnerFlowError, "The Flow step #{node.id} names a version that cannot run" if chosen.version&.out_of_service?
25
26
  Run.start(chosen.flow || raise(ActiveRecord::RecordNotFound), version: chosen.version)
26
27
  .tap { |inner| inner.update!(parent_run: @run, parent_step: node.id, owner: @run.owner) }.advance
@@ -30,10 +31,16 @@ module EasyFlow
30
31
  parent = @run.parent_run or return
31
32
  return if parent.recorded.key?(@run.parent_step.to_sym)
32
33
 
33
- parent.record(@run.parent_step.to_sym, @run.output) if @run.output
34
+ ending = @run.output || ("ended" if chose_from_run?(parent))
35
+ parent.record(@run.parent_step.to_sym, ending) if ending
34
36
  AdvanceParentJob.perform_later(parent, @run.parent_step)
35
37
  end
36
38
 
39
+ def chose_from_run?(parent)
40
+ type = parent.pinned_steps.dig(@run.parent_step, "type")
41
+ EasyFlow.registry.registered?(type) && EasyFlow.registry.fetch(type).chooses_flow_from_run?
42
+ end
43
+
37
44
  def finish(_state)
38
45
  @run
39
46
  end
@@ -74,6 +74,10 @@ module EasyFlow
74
74
  @starts_a_flow = true
75
75
  end
76
76
 
77
+ def chooses_flow_from_run(&chooser)
78
+ @run_chooser = chooser
79
+ end
80
+
77
81
  def chooses_flow(&chooser)
78
82
  @flow_chooser = chooser
79
83
  end
@@ -124,7 +128,7 @@ module EasyFlow
124
128
 
125
129
  def to_step_type
126
130
  StepType.new(id: @id, step_name: @step_name, settings: settings, awaits_input: @awaits_input,
127
- ends_here: @ends_here, begins_here: @begins_here, starts_a_flow: @starts_a_flow, flow_chooser: @flow_chooser, behaviour: @behaviour, routing: @routing,
131
+ ends_here: @ends_here, begins_here: @begins_here, starts_a_flow: @starts_a_flow, flow_chooser: @flow_chooser, run_chooser: @run_chooser, behaviour: @behaviour, routing: @routing,
128
132
  display: @display, drawn_by: @drawn_by, naming_field: @naming_field, naming: @naming,
129
133
  outputs: @declared_outputs, answer_check: @answer_check, answer_labelling: @answer_labelling, readiness: @readiness)
130
134
  end
@@ -7,7 +7,7 @@ module EasyFlow
7
7
  attr_reader :id, :step_name, :settings, :naming_field, :naming, :outputs, :drawn_by
8
8
 
9
9
  def initialize(id:, step_name:, settings:, awaits_input:, behaviour:, routing:,
10
- ends_here: false, begins_here: false, starts_a_flow: false, flow_chooser: nil, display: nil, drawn_by: nil,
10
+ ends_here: false, begins_here: false, starts_a_flow: false, flow_chooser: nil, run_chooser: nil, display: nil, drawn_by: nil,
11
11
  naming_field: nil, naming: nil, outputs: [], answer_check: nil, answer_labelling: nil, readiness: nil)
12
12
  @id = id
13
13
  @step_name = step_name
@@ -17,6 +17,7 @@ module EasyFlow
17
17
  @begins_here = begins_here
18
18
  @starts_a_flow = starts_a_flow
19
19
  @flow_chooser = flow_chooser
20
+ @run_chooser = run_chooser
20
21
  @behaviour = behaviour
21
22
  @routing = routing
22
23
  @display = display
@@ -91,6 +92,14 @@ module EasyFlow
91
92
  @starts_a_flow
92
93
  end
93
94
 
95
+ def chooses_flow_from_run?
96
+ !@run_chooser.nil?
97
+ end
98
+
99
+ def flow_chosen_from_run(node, run)
100
+ @run_chooser&.call(node, run)
101
+ end
102
+
94
103
  def flow_chosen_by(node)
95
104
  @flow_chooser&.call(node)
96
105
  end
@@ -170,7 +170,7 @@ module EasyFlow
170
170
  end
171
171
 
172
172
  def starting_a_flow(document = @document)
173
- document.nodes.select { |node| @registry.registered?(node.type) && @registry.fetch(node.type).starts_a_flow? }
173
+ document.nodes.select { |node| @registry.registered?(node.type) && @registry.fetch(node.type).starts_a_flow? && !@registry.fetch(node.type).chooses_flow_from_run? }
174
174
  end
175
175
 
176
176
  def missing_settings
@@ -1,3 +1,3 @@
1
1
  module EasyFlow
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider