easy_flow 0.54.0 → 0.55.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: 0ac513b344a1d8840cfe5fee24ae751eda1e9f2e24a6b4d1fcd7199091a621d9
4
- data.tar.gz: 9cf5f9b0edff6739beda59b1e5aa23064121ab6211344dcc1792eb407dd67f62
3
+ metadata.gz: 84c894614f26742e63801ba7efc4d168740ad53aa6cbf36dd5df6ed581800e73
4
+ data.tar.gz: d39770774d54283df68d05e735e74f8f1548fa0ee8914e58bc3dc15745a8e3b4
5
5
  SHA512:
6
- metadata.gz: 58ca418648f6f5d8bd2febb3ea4204aa8e296928094c147cba63dd2319ccb772ba8373950410ad0235157902311194147b8c1ebebaf00d51d26045106a43016a
7
- data.tar.gz: 797dec1241a9d2a38d395c75cc4bd4754045d7ad13040981bd7758c738db620ecc7853c200098761532b0d179179785fc533e747f4929808a48f972dcb912327
6
+ metadata.gz: 85dcab8de7bfb5cd9761f7aa616bbb79f49174043a26415366ff6b83c133c9e0c73509d9ef9827919491dd9d6095237831bfab3df004478b6f2ab95c8859b168
7
+ data.tar.gz: 11f039f22f8368d0351afc87d0aa001510f606f746b3353c53f5241a91b096f67a1e013231f98bdb1b5493602606d861976ecd880a8a1349ba597f42668afb51
data/README.md CHANGED
@@ -3,20 +3,55 @@ Guided, versioned, branching flows for Rails apps
3
3
 
4
4
  ## For each
5
5
 
6
- A For each step (`:for_each`) is drawn on the canvas as a dashed box. It runs the steps inside the box once for each item of a list an earlier step recorded, one item after another, in list order. It runs only in a flow that saves its runs, and a flow that keeps nothing tells the visitor so.
6
+ A For each step (`:for_each`) is drawn on the canvas as a dashed box. It runs the steps inside the box once for each item of a list an earlier step recorded, starting items in list order. It runs only in a flow that saves its runs, and a flow that keeps nothing tells the visitor so.
7
7
 
8
8
  Its settings:
9
9
 
10
10
  - `list` names the list as `<step>.<output>`, such as `outline.variants`, or as the step id alone when that step recorded the array as its whole value.
11
- - `concurrency` is how many items may run at the same time. Items still run one at a time.
12
- - `on_item_failure` is `continue` or `stop`. A failed item still lets the next item start.
11
+ - `concurrency` is how many items may be unfinished at the same time. With none set, items run one at a time.
12
+ - `on_item_failure` is `continue` or `stop`. Under `continue`, a failed item ends only that item. Under `stop`, no item starts after an item has failed, and the items already running are allowed to end.
13
+ - `item_limit` is the most items the list may hold. With none set, the limit is 100.
13
14
 
14
- Each visit of a held step is recorded under its item number, counting from 1, such as `write@item2`, and a further visit inside the same item adds the visit number, such as `write@item2@2`. A held step's input can tick `The current item` to receive that item's value from the list. An input naming another held step receives that step's output for the same item. An item ends when its steps leave the box, or when a held step routes to `failed`.
15
+ Each visit of a held step is recorded under its item number, counting from 1, such as `write@item2`, and a further visit inside the same item adds the visit number, such as `write@item2@2`. A held step's input can tick `The current item` to receive that item's value from the list. An input naming another held step receives that step's output for the same item. An item ends when its steps leave the box, or when a held step routes to `failed`. An item counts as running once one of its held steps has a recorded visit.
16
+
17
+ ### Steps ready now
18
+
19
+ `run.next_step(run.recorded)` names one step, as it always has. `run.ready_steps` names every step that may run now. Outside a For each step it holds the next step alone. Inside one it holds the next held step of each unfinished item, never more than `concurrency` of them, in list order.
20
+
21
+ ```ruby
22
+ run.ready_steps.map(&:id)
23
+ # => ["write@item1", "write@item2", "write@item3"]
24
+ run.record("write@item2", { "result" => "passed" })
25
+ run.advance
26
+ run.ready_steps.map(&:id)
27
+ # => ["write@item1", "write@item3", "write@item4"]
28
+ ```
29
+
30
+ `run.advance` runs every acting step among the ready steps, not only the first.
31
+
32
+ ### What it records
15
33
 
16
34
  Once every item has ended, the For each step records these outputs under its own id:
17
35
 
18
36
  - `result` is `passed` when no item failed, and `failed` otherwise.
19
- - `items` holds one entry per item, mapping each held step the item reached to its latest value.
37
+ - `items` holds one entry per item that ran, mapping each held step the item reached to its latest value.
20
38
  - `passed` and `failed` count the items.
39
+ - `reason` says why the step failed when its list could not be run.
21
40
 
22
41
  A step after the box reads them through an input that names the For each step and one of those outputs. An empty list runs no items, records `items` as an empty list, and the run goes on to the step after the box.
42
+
43
+ The run leaves the box on the connection that leaves it from a held step. Under `stop`, once an item has failed and the running items have ended, the run leaves on the `failed` connection of the held step that failed.
44
+
45
+ ### A list that cannot be run
46
+
47
+ The step starts no item and records `result` as `failed` with a `reason` when:
48
+
49
+ - the earlier step recorded no value under the named output, such as `The step outline recorded no value under variants.`
50
+ - the value is not a list, such as `The list outline.variants is text, not a list.`, naming text, a number or a hash.
51
+ - the list holds more items than `item_limit`, such as `The list outline.variants holds 120 items, more than the limit of 100.`
52
+
53
+ The run then leaves on a `failed` connection that leaves the box from a held step. With none, the run stops there, as it does after any failed step with no `failed` connection.
54
+
55
+ ### Reaching it again
56
+
57
+ A run that comes back to a For each step, through a later step that loops back to it or to a step before it, runs the held steps again for each item of the list as it stands then. The second pass records its visits with a pass number after the item, such as `write@item2@pass2` and `write@item2@pass2@2`, and the third pass with `pass3`. The first pass's keys carry no pass number. The For each step records each pass's outputs under its own visit, `variants` for the first and `variants@2` for the second, so both stay readable, and a step after the box reads the latest pass. A held step's input naming another held step reads that step's output for the same item in the same pass.
@@ -1,6 +1,8 @@
1
1
  module EasyFlow
2
2
  class Digest
3
3
  Path = Struct.new(:recorded, :latest, :latest_times)
4
+ ItemWalk = Struct.new(:held, :failed_at, :started)
5
+ ItemsWalk = Struct.new(:ready, :stopped_at, :problem)
4
6
 
5
7
  def initialize(document, registry: EasyFlow.registry)
6
8
  @document = document
@@ -82,7 +84,11 @@ module EasyFlow
82
84
 
83
85
  def items_ended(id, state)
84
86
  box = step(id)
85
- ended = items_of(box, latest_values(state)).each_index.map { |index| item_values(box, index + 1, state) }
87
+ problem = list_problem(box, latest_values(state))
88
+ return { "result" => "failed", "reason" => problem, "items" => [], "passed" => 0, "failed" => 0 } if problem
89
+
90
+ pass = VisitKey.parse(id).visit
91
+ ended = items_of(box, latest_values(state)).each_index.map { |index| item_values(box, index + 1, pass, state) }.reject(&:empty?)
86
92
  failed = ended.count { |values| values.any? { |held, value| failed?(step(held), state.merge(held => value), {}) } }
87
93
 
88
94
  { "result" => failed.zero? ? "passed" : "failed", "items" => ended, "passed" => ended.size - failed, "failed" => failed }
@@ -100,6 +106,10 @@ module EasyFlow
100
106
  walk(state, times)[1]
101
107
  end
102
108
 
109
+ def ready_steps(state, times = {})
110
+ walk(state, times)[3].to_a
111
+ end
112
+
103
113
  def output(state, times = {})
104
114
  ended_setting(state, times, "output")
105
115
  end
@@ -160,9 +170,9 @@ module EasyFlow
160
170
  visits[cursor.id] += 1
161
171
  answers_at_visit[cursor.id] = answered
162
172
  key = visit_key(cursor.id, visits[cursor.id])
163
- held = repeats?(cursor) && walk_items(cursor, state, times, Path.new(recorded, latest, latest_times))
164
- return [ recorded, held ] if held
165
- return [ recorded, cursor.with(id: key) ] if pending?(cursor, key, state)
173
+ items = repeats?(cursor) ? walk_items(cursor, visits[cursor.id], state, times, Path.new(recorded, latest, latest_times)) : ItemsWalk.new([], nil, nil)
174
+ return [ recorded, items.ready.first, nil, items.ready ] if items.ready.any? && !state.key?(key)
175
+ return [ recorded, cursor.with(id: key), nil, [ cursor.with(id: key) ] ] if pending?(cursor, key, state)
166
176
 
167
177
  if state.key?(key)
168
178
  recorded << key
@@ -170,18 +180,26 @@ module EasyFlow
170
180
  latest_times[cursor.id] = times[key] if times.key?(key)
171
181
  answered += 1 if step_type(cursor)&.awaits_input?
172
182
  end
173
- cursor = repeats?(cursor) ? box_exit(cursor) : successor(cursor, reached(state, recorded).merge(latest), latest_times)
183
+ cursor = repeats?(cursor) ? box_exit(cursor, items) : successor(cursor, reached(state, recorded).merge(latest), latest_times)
174
184
  end
175
185
 
176
186
  [ recorded, nil ]
177
187
  end
178
188
 
179
- def walk_items(box, state, times, path)
180
- items_of(box, path.latest).each_index do |index|
181
- held = walk_item(box, index + 1, state, times, path)
182
- return held if held
183
- end
184
- nil
189
+ def walk_items(box, pass, state, times, path)
190
+ walked = items_of(box, path.latest).each_index.map { |index| walk_item(box, VisitKey.new(step: box.id, item: index + 1, pass: pass), state, times, path) }
191
+ stopped_at = walked.find(&:failed_at)&.failed_at if stops_on_failure?(box)
192
+ ready = walked.select(&:held).select { |item| item.started || !stopped_at }.first(concurrency_of(box)).map(&:held)
193
+
194
+ ItemsWalk.new(ready, stopped_at, list_problem(box, path.latest))
195
+ end
196
+
197
+ def stops_on_failure?(box)
198
+ box.config["on_item_failure"].to_s == "stop"
199
+ end
200
+
201
+ def concurrency_of(box)
202
+ [ box.config["concurrency"].to_i, 1 ].max
185
203
  end
186
204
 
187
205
  def walk_item(box, item, state, times, path)
@@ -189,24 +207,28 @@ module EasyFlow
189
207
  recorded_at_visit = {}
190
208
  cursor = first_held(box)
191
209
 
210
+ started = false
211
+
192
212
  while cursor && held_by?(box, cursor)
193
- return if visits[cursor.id].positive? && recorded_at_visit[cursor.id] == path.recorded.size
213
+ return ItemWalk.new(nil, nil, started) if visits[cursor.id].positive? && recorded_at_visit[cursor.id] == path.recorded.size
194
214
 
195
215
  visits[cursor.id] += 1
196
216
  recorded_at_visit[cursor.id] = path.recorded.size
197
- key = item_key(cursor.id, item, visits[cursor.id])
198
- return cursor.with(id: key) if pending?(cursor, key, state)
217
+ key = item.with(step: cursor.id, visit: visits[cursor.id]).to_s
218
+ return ItemWalk.new(cursor.with(id: key), nil, started) if pending?(cursor, key, state)
199
219
 
200
220
  if state.key?(key)
221
+ started = true
201
222
  path.recorded << key
202
223
  path.latest[cursor.id] = state[key]
203
224
  path.latest_times[cursor.id] = times[key] if times.key?(key)
204
225
  end
205
226
  routed = reached(state, path.recorded).merge(path.latest)
206
- return if failed?(cursor, routed, path.latest_times)
227
+ return ItemWalk.new(nil, cursor, started) if failed?(cursor, routed, path.latest_times)
207
228
 
208
229
  cursor = successor(cursor, routed, path.latest_times)
209
230
  end
231
+ ItemWalk.new(nil, nil, started)
210
232
  end
211
233
 
212
234
  def failed?(node, state, times)
@@ -214,14 +236,37 @@ module EasyFlow
214
236
  end
215
237
 
216
238
  def items_of(box, latest)
239
+ list_problem(box, latest) ? [] : listed_value(box, latest)
240
+ end
241
+
242
+ def listed_value(box, latest)
217
243
  step_id, output = step_type(box).list_named_by(box).split(".", 2)
218
244
  listed = latest[step_id]
219
- listed = listed[output] if listed.is_a?(Hash) && output
220
- listed.is_a?(Array) ? listed : []
245
+ listed.is_a?(Hash) && output ? listed[output] : listed
246
+ end
247
+
248
+ def list_problem(box, latest)
249
+ named = step_type(box).list_named_by(box)
250
+ step_id, output = named.split(".", 2)
251
+ listed = listed_value(box, latest)
252
+ return "The step #{step_id} recorded no value#{" under #{output}" if output}." if listed.nil?
253
+
254
+ return "The list #{named} is #{kind_of_value(listed)}, not a list." unless listed.is_a?(Array)
255
+
256
+ "The list #{named} holds #{listed.size} items, more than the limit of #{item_limit_of(box)}." if listed.size > item_limit_of(box)
221
257
  end
222
258
 
223
- def item_key(id, item, visit)
224
- VisitKey.new(step: id, item: item, visit: visit).to_s
259
+ def item_limit_of(box)
260
+ box.config["item_limit"].presence&.to_i || ForEach::ITEM_LIMIT
261
+ end
262
+
263
+ def kind_of_value(value)
264
+ case value
265
+ when String then "text"
266
+ when Numeric then "a number"
267
+ when Hash then "a hash"
268
+ else "true or false"
269
+ end
225
270
  end
226
271
 
227
272
  def latest_values(state)
@@ -229,8 +274,8 @@ module EasyFlow
229
274
  .transform_values { |visits| state[visits.max_by(&:visit).to_s] }
230
275
  end
231
276
 
232
- def item_values(box, item, state)
233
- visits = state.keys.map { |key| VisitKey.parse(key) }.select { |visit| visit.item == item }
277
+ def item_values(box, item, pass, state)
278
+ visits = state.keys.map { |key| VisitKey.parse(key) }.select { |visit| visit.item == item && visit.pass == pass }
234
279
  Array(box.config["holds"]).filter_map do |held|
235
280
  latest = visits.select { |visit| visit.step == held }.max_by(&:visit)
236
281
  [ held, state[latest.to_s] ] if latest
@@ -246,9 +291,13 @@ module EasyFlow
246
291
  entering && @document.node(entering.to)
247
292
  end
248
293
 
249
- def box_exit(box)
294
+ def box_exit(box, items)
250
295
  held = Array(box.config["holds"])
251
- leaving = @document.edges.find { |edge| held.include?(edge.from) && !held.include?(edge.to) && edge.on.to_s != "failed" }
296
+ leaving = @document.edges.select { |edge| held.include?(edge.from) && !held.include?(edge.to) }.find do |edge|
297
+ next edge.from == items.stopped_at.id && edge.on.to_s == "failed" if items.stopped_at
298
+
299
+ items.problem ? edge.on.to_s == "failed" : edge.on.to_s != "failed"
300
+ end
252
301
  leaving && @document.node(leaving.to)
253
302
  end
254
303
 
@@ -2,6 +2,8 @@ module EasyFlow
2
2
  class ForEach
3
3
  include Step
4
4
 
5
+ ITEM_LIMIT = 100
6
+
5
7
  step_name "For each"
6
8
 
7
9
  holds_steps
@@ -11,6 +13,7 @@ module EasyFlow
11
13
  setting :list, type: :string
12
14
  setting :concurrency, type: :integer
13
15
  setting :on_item_failure, type: :select, options: %w[continue stop]
16
+ setting :item_limit, type: :integer, label: "Most items"
14
17
 
15
18
  output :result, values: %w[passed failed]
16
19
  output :items
@@ -26,16 +26,16 @@ module EasyFlow
26
26
  private_class_method :value_of
27
27
 
28
28
  def self.latest_output(node, input, state, run)
29
- latest_visit = latest_visit_of(input["step"], VisitKey.parse(node.id).item, state)
29
+ latest_visit = latest_visit_of(input["step"], VisitKey.parse(node.id), state)
30
30
  return if unreported?(input, state[latest_visit], run)
31
31
 
32
32
  CompletedAt.value_of(state, {}, latest_visit, input["output"])
33
33
  end
34
34
  private_class_method :latest_output
35
35
 
36
- def self.latest_visit_of(step, item, state)
36
+ def self.latest_visit_of(step, reader, state)
37
37
  visits = state.keys.to_h { |key| [ key, VisitKey.parse(key) ] }.select { |_key, visit| visit.step == step }
38
- same_item = visits.select { |_key, visit| visit.item == item }
38
+ same_item = visits.select { |_key, visit| visit.item == reader.item && visit.pass == reader.pass }
39
39
  (same_item.presence || visits.reject { |_key, visit| visit.item }).max_by { |_key, visit| visit.visit }&.first
40
40
  end
41
41
  private_class_method :latest_visit_of
@@ -40,6 +40,10 @@ module EasyFlow
40
40
  digest.next_step(state.transform_keys(&:to_s), completed_at.transform_keys(&:to_s))
41
41
  end
42
42
 
43
+ def ready_steps(state = recorded)
44
+ digest.ready_steps(state.transform_keys(&:to_s), completed_at.transform_keys(&:to_s))
45
+ end
46
+
43
47
  def ended_at_end?
44
48
  digest.ended_at_end?(recorded.transform_keys(&:to_s), completed_at.transform_keys(&:to_s))
45
49
  end
@@ -29,11 +29,12 @@ module EasyFlow
29
29
  end
30
30
 
31
31
  def run(progress)
32
- while (node = @digest.next_step(named(progress.recorded), named(progress.completed_at))) && goes_on?(node, named(progress.recorded), CompletedAt.latest(named(progress.completed_at))) && (progress.saved? || refusal_of(node).nil?)
33
- progress.record(node.id, result_of(@digest.step(node.id), named(progress.recorded), progress.run))
32
+ while (node = going_on(progress))
33
+ progress.record(node.id, result_of(node, named(progress.recorded), progress.run))
34
34
  end
35
- progress.start_inner(node) if node && starts_a_flow?(node)
36
- progress.ended unless node
35
+ waiting = @digest.next_step(named(progress.recorded), named(progress.completed_at))
36
+ progress.start_inner(waiting) if waiting && starts_a_flow?(waiting)
37
+ progress.ended unless waiting
37
38
  end
38
39
 
39
40
  def unsaved_refusal(state, times: {})
@@ -63,6 +64,13 @@ module EasyFlow
63
64
 
64
65
  private
65
66
 
67
+ def going_on(progress)
68
+ state = named(progress.recorded)
69
+ @digest.ready_steps(state, named(progress.completed_at)).find do |node|
70
+ goes_on?(node, state, CompletedAt.latest(named(progress.completed_at))) && (progress.saved? || refusal_of(node).nil?)
71
+ end
72
+ end
73
+
66
74
  def refusal_of(node)
67
75
  own_refusal(node) || own_refusal(node && @digest.holder_of(node.id))
68
76
  end
@@ -103,9 +111,10 @@ module EasyFlow
103
111
  @registry.registered?(node.type) && @registry.fetch(node.type).waits? && @registry.fetch(node.type).ready?(node, state, times)
104
112
  end
105
113
 
106
- def result_of(node, state, run)
114
+ def result_of(visited, state, run)
115
+ node = @digest.step(visited.id)
107
116
  return allowed(node, state).first.to_s if decided?(node, state)
108
- return @digest.items_ended(node.id, state) if @digest.repeats?(node)
117
+ return @digest.items_ended(visited.id, state) if @digest.repeats?(node)
109
118
 
110
119
  acts?(node) ? @registry.fetch(node.type).process(node, state, run: run) : true
111
120
  end
@@ -1,13 +1,18 @@
1
1
  module EasyFlow
2
- VisitKey = Data.define(:step, :item, :visit) do
2
+ VisitKey = Data.define(:step, :item, :visit, :pass) do
3
3
  def self.parse(key)
4
4
  step, *rest = key.to_s.split("@")
5
5
  item = rest.shift.delete_prefix("item").to_i if rest.first.to_s.start_with?("item")
6
- new(step: step, item: item, visit: (rest.first || 1).to_i)
6
+ pass = rest.shift.delete_prefix("pass").to_i if rest.first.to_s.start_with?("pass")
7
+ new(step: step, item: item, visit: (rest.first || 1).to_i, pass: pass || 1)
8
+ end
9
+
10
+ def initialize(step:, item: nil, visit: 1, pass: 1)
11
+ super
7
12
  end
8
13
 
9
14
  def to_s
10
- [ step, ("item#{item}" if item), (visit if visit > 1) ].compact.join("@")
15
+ [ step, ("item#{item}" if item), ("pass#{pass}" if pass > 1), (visit if visit > 1) ].compact.join("@")
11
16
  end
12
17
  end
13
18
  end
@@ -1,3 +1,3 @@
1
1
  module EasyFlow
2
- VERSION = "0.54.0"
2
+ VERSION = "0.55.0"
3
3
  end
@@ -592,20 +592,26 @@ Use this when a visitor's run should stop until a set time has passed, such as a
592
592
  1. Ask the developer which earlier step records the list, and under which of its outputs. The list must be recorded as an array, such as `{ "variants" => ["short", "long"] }`.
593
593
  2. On the canvas, place a For each step and fill in its settings:
594
594
  - `List` — the earlier step and its output as text, `<step>.<output>`, such as `outline.variants`, or the step id alone when it records the array as its plain value.
595
- - `Concurrency` — how many items may run at the same time. It is saved and shown in the box's header, and items still run one after another.
596
- - `On item failure` — `continue` or `stop`. It is saved and shown in the box's header, and a failed item still lets the next item start.
595
+ - `Concurrency` — how many items may be unfinished at the same time. With none set, items run one at a time.
596
+ - `On item failure` — `continue` or `stop`. Under `continue` a failed item ends only that item. Under `stop` no item starts after an item has failed, the items already running are allowed to end, and the run then leaves on the `failed` connection of the held step that failed.
597
+ - `Most items` — stored as `item_limit`, the most items the list may hold. With none set, the limit is 100.
597
598
  3. Drag the steps to run per item into the box. Connect the For each step to the first held step, connect the held steps to each other, and connect the last held step to the step after the box.
598
599
  4. Publish the flow set to save each step. A For each step reached in a flow set to save on finish or to save nothing shows the visitor `Steps can only be run for each item in a flow that saves its runs.` and goes no further, at the For each step or at any step it holds.
599
600
  5. What then holds when a stored run reaches the For each step:
600
- - The run walks the held steps for item 1, then item 2, and so on in list order, one item at a time.
601
+ - The run starts items in list order and keeps no more than `concurrency` of them unfinished at once. An item counts as running once one of its held steps has a recorded visit.
601
602
  - Each visit of a held step is recorded under `<step>@item<n>`, counting items from 1, such as `write@item2`. A held step visited again inside one item, such as after a `retry` connection back to itself, is recorded as `<step>@item<n>@<visit>`, such as `write@item2@2`, and other items' visits are left as they were.
602
- - `run.next_step(run.recorded)` returns the held step to run next with that key as its `id`, so the app records its value with `run.record(step.id, value)` and reads its inputs with `EasyFlow::Inputs.values_of(step, run.recorded.stringify_keys, run: run)`.
603
+ - `run.next_step(run.recorded)` returns one held step to run next with that key as its `id`, so the app records its value with `run.record(step.id, value)` and reads its inputs with `EasyFlow::Inputs.values_of(step, run.recorded.stringify_keys, run: run)`.
604
+ - `run.ready_steps` returns every step that may run now: the next held step of each unfinished item, up to `concurrency` of them, and outside a For each step the next step alone. An app that hands out several steps at once reads this list, and an app that reads only `next_step` keeps working one item at a time. `run.advance` runs every acting step among them.
603
605
  - An item ends when its walk leaves the box, or when a held step's `route` returns `"failed"`, and the next item starts.
604
- - Once every item has ended, `run.advance` records the For each step's own value under its id: `result` is `"passed"` when no item failed and `"failed"` otherwise, `items` is an array with one hash per item mapping each held step it reached to that step's latest value for the item, and `passed` and `failed` count the items.
605
- - A list that is missing, is not an array or is empty runs no items, records `items` as `[]`, and the run goes on to the step after the box.
606
+ - Once every item has ended, `run.advance` records the For each step's own value under its id: `result` is `"passed"` when no item failed and `"failed"` otherwise, `items` is an array with one hash per item that ran mapping each held step it reached to that step's latest value for the item, and `passed` and `failed` count the items.
607
+ - An empty list runs no items, records `items` as `[]`, and the run goes on to the step after the box.
608
+ - A list that is missing, is not an array, or holds more items than the limit starts no item and records `{ "result" => "failed", "reason" => ..., "items" => [], "passed" => 0, "failed" => 0 }`. The reason names the step and output, the value's kind (text, a number or a hash), or the limit. The run then leaves on a `failed` connection leaving the box from a held step, and with none it stops there, as after any failed step with no `failed` connection.
609
+ - A run that reaches the For each step again, through a later step looping back, runs the held steps again for each item of the list as it stands then. The second pass's visits are keyed `<step>@item<n>@pass2`, or `<step>@item<n>@pass2@<visit>` for a further visit, and the first pass's keys carry no pass. Each pass's outputs are recorded under the For each step's own visit, such as `variants` and `variants@2`, and a step after the box reads the latest pass.
606
610
  - A step after the box reads `result`, `items`, `passed` or `failed` through an input naming the For each step and that output.
607
611
 
608
612
  ```ruby
613
+ run.ready_steps.map(&:id)
614
+ # => ["write@item2", "write@item3", "write@item4"]
609
615
  step = run.next_step(run.recorded)
610
616
  step.id
611
617
  # => "write@item2"
@@ -683,7 +689,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
683
689
  - A run starts only on a version its own flow has published and not retired or withdrawn, and any other version raises `ActiveRecord::RecordInvalid`.
684
690
  - Always read a run against `run.pinned_definition`, never the flow's live version, since a run keeps the version it started on after a new one is published.
685
691
  - Always look flows and runs up through a host.
686
- - In a flow that loops, a later visit's answer is keyed `<id>@<n>`, and a step held by a For each step is keyed `<id>@item<n>` or `<id>@item<n>@<visit>`, so code that reads answers never assumes one answer per step id, and takes the part of a key before the first `@` to find its step.
692
+ - In a flow that loops, a later visit's answer is keyed `<id>@<n>`, and a step held by a For each step is keyed `<id>@item<n>`, `<id>@item<n>@<visit>`, or with `@pass<n>` after the item on a later pass, so code that reads answers never assumes one answer per step id, and takes the part of a key before the first `@` to find its step.
687
693
  - A Count step and any code that reads every visit of a step together count a held step's visits across all items. A step id may not contain `@`, and a flow with one is refused when published.
688
694
  - A loop that comes back to a step with no answer given since the last visit to it ends the flow there and `run.stopped_on_loop` names that step, so every loop needs a step that awaits input.
689
695
  - `run.ended_at_end?` is `true` only for a run whose last step reached is of an `ends_here` type, so a run a loop stopped, or one that ended at a step with no connection to follow, is never counted as ended at an End step.
@@ -36,7 +36,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
36
36
  - To let a visitor tick several answers on one step, no code is needed: an admin places a checklist step on the canvas.
37
37
  - To explain an answer to the visitor, no code is needed: an admin fills in that answer's info on a question or checklist step.
38
38
  - To start another flow from inside a flow, no code is needed: an admin places a Flow step on the canvas and picks that flow and its version. The connections leaving the step are labelled with the ways that flow can end, and a stored run moves on along the one named after the output its inner run ended with. Clicking the step's card opens the canvas of the flow it runs, and that canvas has a button back to the flow it was opened from. A Flow step cannot start the flow it sits in, directly or through other flows.
39
- - To run some steps once for each item of a list an earlier step recorded, no step type is needed: an admin places a For each step on the canvas, names the list as `<step>.<output>`, and drags the steps into its box. A stored run walks the held steps for each item in list order, one item at a time, records each visit under `<step>@item<n>`, and once every item has ended records the For each step's `result`, `items`, `passed` and `failed`, which later steps read as inputs. A flow that keeps nothing refuses to run it. Reading those keys from the app's own code is in **easy_flow-develop**.
39
+ - To run some steps once for each item of a list an earlier step recorded, no step type is needed: an admin places a For each step on the canvas, names the list as `<step>.<output>`, and drags the steps into its box. A stored run starts items in list order, keeps up to the step's concurrency of them unfinished at once and names every step ready now through `run.ready_steps`, records each visit under `<step>@item<n>`, and once every item has ended records the For each step's `result`, `items`, `passed` and `failed`, which later steps read as inputs. Under the `stop` rule no item starts after one fails. A list that is missing, is not a list or is longer than the step's item limit, 100 unless set, fails the step with a `reason`. A run that reaches the step again runs its items again as a new pass keyed `<step>@item<n>@pass<n>`. A flow that keeps nothing refuses to run it. Reading those keys from the app's own code is in **easy_flow-develop**.
40
40
  - To add another step type that holds other steps, use **easy_flow-develop**. Once one is offered, an admin places it on the canvas and drags steps into its box, with no further code.
41
41
  - To ask a step again, such as repeating a question until the visitor says they are done, no code is needed: an admin connects a later step back to an earlier one on the canvas.
42
42
  - To end a loop after a number of tries, no code is needed: an admin places a Count step after the step being repeated and a Compare step after the Count step, and connects the Compare step's false connection back to the repeated step.
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.54.0
4
+ version: 0.55.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider