easy_flow 0.4.7 → 0.4.9

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: 92d52fb553f82cf1f206f0257d5d4fdaa0718ec6197ccabf016e6b20107371da
4
- data.tar.gz: 66a5f5930c064d692b3c8b410174119e697c97b6a9ec47e8e9bffccd7abf7f5c
3
+ metadata.gz: 310df5972d6ca11a6862e8c101b79f8802adbe620ee90e3c8764cda70feb9492
4
+ data.tar.gz: c43a02f417356eb7bf31e2e53fa220a4d32b7fefed055ed031dda114eccec951
5
5
  SHA512:
6
- metadata.gz: a982c31c2a100d8f74b6d75346200f68c1aad256e2ff87b24267fc509fca46ef19da19fb169f48798d4f33cf44d6dee011164f2a7df3dc4107b9b1cdbe081b43
7
- data.tar.gz: 97ee4e459a2c25a0ef77b5433e056cfa83ccc40a9b0cf73abad201b9fcec9d5ea6e8079396d6d7ad4ed3ec904d7035c103b9ba045fd81d394096c339903cda80
6
+ metadata.gz: 82e5b5eede06952c31b553577668d70499b828e576f5acc2e96964a30f8c897c6762d8e450674d5774d2c54034c0309019cf68138ddc45d9de48b165659bfe29
7
+ data.tar.gz: 0ad147aae3a60c96b225122d43d7f73e570c275b101b7c74db0bf00389ac01e927026ae5428925c3f9f8887d88a14f1266d82cd5299972b4f53dba7b75e32f9c
@@ -6,7 +6,7 @@ module EasyFlow
6
6
  private
7
7
 
8
8
  def canvas_payload(flow)
9
- Canvas.new(canvas_document(flow)).to_h
9
+ Canvas.new(canvas_document(flow), host: flow_host).to_h
10
10
  .merge("undoable" => flow.edit_history.undoable?, "redoable" => flow.edit_history.redoable?,
11
11
  "changes" => listed_changes(flow), "flow" => flow_details(flow))
12
12
  end
@@ -18,6 +18,7 @@ module EasyFlow
18
18
  @question = @guide.next_step(@answers)
19
19
  @drawing = @guide.drawing_at(@answers)
20
20
  flash.now[:alert] = @refused if @refused
21
+ @waiting = waiting_on(@question)
21
22
  return render :step if @question
22
23
 
23
24
  render_completion
@@ -124,6 +125,13 @@ module EasyFlow
124
125
  progress.record(id, value.to_s)
125
126
  end
126
127
 
128
+ def waiting_on(step)
129
+ return unless step.respond_to?(:type) && EasyFlow.registry.registered?(step.type)
130
+
131
+ step_type = EasyFlow.registry.fetch(step.type)
132
+ step_type.name_of(step).presence || step_type.step_name if step_type.waits?
133
+ end
134
+
127
135
  def answer_problem(step, answer)
128
136
  return unless step && EasyFlow.registry.registered?(step.type)
129
137
 
@@ -1,8 +1,9 @@
1
1
  module EasyFlow
2
2
  class Canvas
3
- def initialize(document, registry: EasyFlow.registry)
3
+ def initialize(document, registry: EasyFlow.registry, host: nil)
4
4
  @document = document
5
5
  @registry = registry
6
+ @host = host
6
7
  end
7
8
 
8
9
  def to_h
@@ -81,7 +82,7 @@ module EasyFlow
81
82
  end
82
83
 
83
84
  def palette
84
- @registry.step_types.reject(&:begins_here?).map do |step_type|
85
+ @registry.step_types.reject(&:begins_here?).select { |step_type| @host.nil? || step_type.ends_here? || @host.offers?(step_type.id) }.map do |step_type|
85
86
  { "type" => step_type.id.to_s, "label" => step_type.step_name,
86
87
  "fields" => step_type.settings.fields.transform_keys(&:to_s).transform_values(&:to_s),
87
88
  "labels" => step_type.settings.labels.transform_keys(&:to_s),
@@ -92,7 +92,7 @@ module EasyFlow
92
92
  def pending?(node, state)
93
93
  return false if state.key?(node.id)
94
94
 
95
- step_type(node)&.awaits_input? || acts?(node)
95
+ step_type(node)&.awaits_input? || acts?(node) || step_type(node)&.waits? || false
96
96
  end
97
97
 
98
98
  def acts?(node)
@@ -18,6 +18,10 @@ module EasyFlow
18
18
  super.to_h.symbolize_keys
19
19
  end
20
20
 
21
+ def advance
22
+ Runner.new(pinned_definition).run(Progress::Kept.new(self))
23
+ end
24
+
21
25
  def pinned_definition
22
26
  definition_version.definition.to_h
23
27
  end
@@ -27,8 +27,8 @@ module EasyFlow
27
27
  end
28
28
 
29
29
  def run(progress)
30
- while (node = @digest.next_step(named(progress.recorded))) && acts?(node)
31
- progress.record(node.id, @registry.fetch(node.type).process(node, named(progress.recorded)))
30
+ while (node = @digest.next_step(named(progress.recorded))) && goes_on?(node, named(progress.recorded))
31
+ progress.record(node.id, result_of(node, named(progress.recorded)))
32
32
  end
33
33
  end
34
34
 
@@ -50,6 +50,18 @@ module EasyFlow
50
50
  @registry.registered?(node.type) && @registry.fetch(node.type).acts?
51
51
  end
52
52
 
53
+ def goes_on?(node, state)
54
+ acts?(node) || ready?(node, state)
55
+ end
56
+
57
+ def ready?(node, state)
58
+ @registry.registered?(node.type) && @registry.fetch(node.type).waits? && @registry.fetch(node.type).ready?(node, state)
59
+ end
60
+
61
+ def result_of(node, state)
62
+ acts?(node) ? @registry.fetch(node.type).process(node, state) : true
63
+ end
64
+
53
65
  def shown(node)
54
66
  return node unless node && @registry.registered?(node.type)
55
67
 
@@ -44,6 +44,10 @@ module EasyFlow
44
44
  @answer_check = check
45
45
  end
46
46
 
47
+ def waits_until(&readiness)
48
+ @readiness = readiness
49
+ end
50
+
47
51
  def step_name(value)
48
52
  @step_name = value
49
53
  end
@@ -107,7 +111,7 @@ module EasyFlow
107
111
  StepType.new(id: @id, step_name: @step_name, settings: settings, awaits_input: @awaits_input,
108
112
  ends_here: @ends_here, begins_here: @begins_here, behaviour: @behaviour, routing: @routing,
109
113
  display: @display, drawn_by: @drawn_by, naming_field: @naming_field, naming: @naming,
110
- outputs: @declared_outputs, answer_check: @answer_check)
114
+ outputs: @declared_outputs, answer_check: @answer_check, readiness: @readiness)
111
115
  end
112
116
 
113
117
  def settings
@@ -8,7 +8,7 @@ module EasyFlow
8
8
 
9
9
  def initialize(id:, step_name:, settings:, awaits_input:, behaviour:, routing:,
10
10
  ends_here: false, begins_here: false, display: nil, drawn_by: nil,
11
- naming_field: nil, naming: nil, outputs: [], answer_check: nil)
11
+ naming_field: nil, naming: nil, outputs: [], answer_check: nil, readiness: nil)
12
12
  @id = id
13
13
  @step_name = step_name
14
14
  @settings = settings
@@ -23,6 +23,7 @@ module EasyFlow
23
23
  @naming = naming
24
24
  @outputs = outputs
25
25
  @answer_check = answer_check
26
+ @readiness = readiness
26
27
  end
27
28
 
28
29
  def display_of(node)
@@ -41,6 +42,14 @@ module EasyFlow
41
42
  @answer_check&.call(node, value)
42
43
  end
43
44
 
45
+ def waits?
46
+ @readiness.present?
47
+ end
48
+
49
+ def ready?(node, state)
50
+ @readiness.call(node, state)
51
+ end
52
+
44
53
  def name_of(node)
45
54
  @naming&.call(node).presence || node.config[naming_field.to_s].presence
46
55
  end
@@ -11,22 +11,26 @@
11
11
  <div class="mb-6"><%= ui_alert(message: flash[:alert], type: :error) %></div>
12
12
  <% end %>
13
13
 
14
- <%= form_with url: step_form[:url], method: step_form[:method], data: { turbo: false } do %>
15
- <%= hidden_field_tag :asked, @question.id %>
16
- <% if carries_answers? %>
17
- <% @answers.each do |key, value| %>
18
- <%= hidden_field_tag "answers[#{key}]", value %>
14
+ <% if @waiting %>
15
+ <p class="text-gray-700">Waiting for <%= @waiting %>.</p>
16
+ <% else %>
17
+ <%= form_with url: step_form[:url], method: step_form[:method], data: { turbo: false } do %>
18
+ <%= hidden_field_tag :asked, @question.id %>
19
+ <% if carries_answers? %>
20
+ <% @answers.each do |key, value| %>
21
+ <%= hidden_field_tag "answers[#{key}]", value %>
22
+ <% end %>
19
23
  <% end %>
20
- <% end %>
21
24
 
22
- <%= render @drawing, step: @question %>
25
+ <%= render @drawing, step: @question %>
23
26
 
24
- <div class="mt-8 flex items-center gap-4">
25
- <%= ui_button(label: "Next", type: :submit) %>
27
+ <div class="mt-8 flex items-center gap-4">
28
+ <%= ui_button(label: "Next", type: :submit) %>
26
29
 
27
- <% if @answers.any? %>
28
- <button type="submit" name="back" value="1" formnovalidate class="cursor-pointer text-sm text-gray-500 underline underline-offset-2 hover:text-gray-900">← Back</button>
29
- <% end %>
30
- </div>
30
+ <% if @answers.any? %>
31
+ <button type="submit" name="back" value="1" formnovalidate class="cursor-pointer text-sm text-gray-500 underline underline-offset-2 hover:text-gray-900">← Back</button>
32
+ <% end %>
33
+ </div>
34
+ <% end %>
31
35
  <% end %>
32
36
  <% end %>
@@ -1,7 +1,7 @@
1
1
  module EasyFlow
2
2
  class Host
3
3
  attr_reader :name
4
- attr_writer :layout, :admin_layout
4
+ attr_writer :layout, :admin_layout, :offers
5
5
  attr_accessor :admin_authentication_method, :visitor_authorization_method, :refusal_method
6
6
 
7
7
  def initialize(name)
@@ -23,5 +23,9 @@ module EasyFlow
23
23
  def set_up?
24
24
  true
25
25
  end
26
+
27
+ def offers?(step_type)
28
+ @offers.nil? || @offers.map(&:to_s).include?(step_type.to_s)
29
+ end
26
30
  end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module EasyFlow
2
- VERSION = "0.4.7"
2
+ VERSION = "0.4.9"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-develop
3
- description: Use PROACTIVELY for adding a step type to easy_flow flows (a step that asks the visitor something, computes a value from earlier answers, or picks the next branch), refusing a blank or invalid answer to a step with a message, offering an admin a step setting whose options are read from the app's own records, serving a host's flows from the app's own controller and routes, acting when a visitor finishes a flow, and reading a run's recorded answers and question labels — MUST BE USED instead of hand-rolling questionnaire steps, branching logic, number comparisons, hard-coded setting options, answer validation, flow controllers or answer lookups.
3
+ description: Use PROACTIVELY for adding a step type to easy_flow flows (a step that asks the visitor something, computes a value from earlier answers, picks the next branch, or holds the visitor until something outside the flow has happened), moving a paused run on once what it waits for has happened, refusing a blank or invalid answer to a step with a message, offering an admin a step setting whose options are read from the app's own records, serving a host's flows from the app's own controller and routes, acting when a visitor finishes a flow, and reading a run's recorded answers and question labels — MUST BE USED instead of hand-rolling questionnaire steps, branching logic, number comparisons, hard-coded setting options, answer validation, polling or "come back later" pages, flow controllers or answer lookups.
4
4
  tools: Read, Write, Edit, Grep
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -18,7 +18,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
18
18
  - `EasyFlow::FlowsController` — the visitor controller; the app subclasses it to serve one host's flows from its own routes and to change what happens at the start, on each step and at the finish.
19
19
  - `hosted_by` — class method on a `FlowsController` subclass naming the host whose flows it serves.
20
20
  - `routed_by` — class method on a `FlowsController` subclass naming the prefix of the app's own route names that the controller redirects and links to.
21
- - `EasyFlow::Run` — the stored record of one visitor's pass through a flow, pinned to the version that was live when it started.
21
+ - `EasyFlow::Run` — the stored record of one visitor's pass through a flow, pinned to the version that was live when it started, and moved on past a waiting step with `advance`.
22
22
  - `EasyFlow::QuestionRunner` — reads a flow document: its steps, the next step for a set of answers, the answers on the path taken, and a question's text and an answer's label.
23
23
 
24
24
  ## How to use it
@@ -29,7 +29,8 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
29
29
  - It asks the visitor for input — declare `awaits_input`.
30
30
  - It computes a value from earlier answers with no visitor input — define `process`.
31
31
  - It only picks which connection to follow — define `route`.
32
- A type may both `process` and `route`. A type that does none of the three is passed through without stopping when a visitor reaches it.
32
+ - It holds the visitor until something outside the flow has happened, such as a payment arriving or a reviewer approving — declare `waits_until`.
33
+ A type may both `process` and `route`. A type that does none of the four is passed through without stopping when a visitor reaches it.
33
34
  2. Create the class in the app, for example `app/models/flow_steps/rating.rb`. The class name, underscored, is the type's id (`Rating` becomes `:rating`), and that id is stored in every flow that uses it, so it must not change after admins start using the type. It must not be one of the built-in ids `start`, `terminal`, `question`, `condition`, `switch` or `compare`:
34
35
 
35
36
  ```ruby
@@ -72,17 +73,19 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
72
73
  ```
73
74
 
74
75
  A step whose type is not registered is neither shown nor run as that type.
75
- 4. Use these words to declare the type. Each is called once at class level (or inside the `EasyFlow.step` block):
76
+ 4. Ask the developer which hosts' admins should be able to add the type. A registered type is in a host's palette, the step types an admin can add on that host's canvas, only when the host names no list of offered step types or its list includes the type's id. A type that declares `ends_here` is in every host's palette, and a type that declares `begins_here` is in none. When a host that names a list should offer the new type, add the type's id to that host's list through `easy_flow-install`. Leaving a type off a host's list only keeps admins from adding it there, and a step of that type already in one of the host's flows is still drawn and run.
77
+ 5. Use these words to declare the type. Each is called once at class level (or inside the `EasyFlow.step` block):
76
78
  - `step_name "<label>"` — the name admins see on the canvas. Defaults to the id.
77
79
  - `setting :name, type:, label:, options:, required:, limit:, check:, from:, outputs_of:` — a field the admin fills in on the canvas. `type` is one of `:string`, `:integer`, `:float`, `:boolean`, `:select`, `:multi_select`, `:previous_step`, `:from_step`, `:list`, or boot raises `EasyFlow::UnknownFieldType`. A `:select` or `:multi_select` must pass `options:`, or boot raises the same error. `options:` is either an array of strings, or a lambda taking no arguments that returns one; the lambda is called each time the canvas is opened and each time an admin saves the step's settings, so the options follow the app's data without a restart (`options: -> { Region.order(:name).pluck(:code) }`). A saved setting whose value is no longer among the options is refused the next time the admin saves that step. When the options come from the app's records, ask the developer which records, which column is stored as the value, and whether the list must differ by account or host, since the lambda is passed nothing and the same list is offered everywhere the type is used. A `:list` must take a block of `setting` calls describing one entry. `:previous_step` lets the admin pick an earlier step, and is always required. `outputs_of: :<setting>` offers the outputs of the step chosen in that setting, and `from: :<setting>` offers the values of the output chosen in that setting; either one makes the type `:from_step`. `limit:` is the most values a `:multi_select` takes. `check:` is a lambda given the value that returns an error message, or `nil` when the value is acceptable. `label:` defaults to the name humanized.
78
80
  - `output :name, type:, label:, values:, from:` — a value the step records. `type` is one of `:string`, `:integer`, `:float`, `:boolean`, or boot raises `EasyFlow::UnknownOutputType`. `values:` is an array or a lambda taking the node, listing the values the output can take; the canvas offers these as the connections leaving the step, so a type that routes must declare them. `from: :<setting>` takes the values from the step chosen in that setting.
79
81
  - `names_by :setting` or `names_by { |node| ... }` — what the step is called on the canvas, from a setting or computed.
80
82
  - `awaits_input` — the visitor is shown this step and submits an answer to it.
83
+ - `waits_until { |node, state| ... }` — the run stops at this step until the block returns a truthy value. See step 8.
81
84
  - `answer_check { |node, value| ... }` — checks a submitted answer before it is recorded. `value` is the submitted string, or `nil` when the input sent nothing. Return a message to refuse the answer, or `nil` to accept it. Without it every answer is accepted, including a blank one.
82
85
  - `ends_here` / `begins_here` — marks the type as an end or a start of a flow.
83
86
  - `displays_by { |node| ... }` — builds the object handed to the step's partial as the local `step`. Without it the partial receives the node itself.
84
87
  - `drawn_by "<partial>"` — the partial that draws this type for a visitor. Without it the host's default drawing is used, which expects `step.id`, `step.text` and `step.choices`, so a type with its own display shape needs its own partial.
85
- 5. For a type that computes or routes, define instance methods on the class (or `process { |node, state| ... }` / `route { |node, state| ... }` in the block form):
88
+ 6. For a type that computes or routes, define instance methods on the class (or `process { |node, state| ... }` / `route { |node, state| ... }` in the block form):
86
89
 
87
90
  ```ruby
88
91
  def process(node, state)
@@ -99,7 +102,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
99
102
  - `process` returns the value recorded under this step's id. It runs as soon as a visitor reaches the step, before the next step is shown.
100
103
  - A type that declares more than one `output` returns a hash from `process`, keyed by each output's name as a string. A later compare step reads the output the admin picks from that hash.
101
104
  - `route` returns the value that picks the connection to follow; it is compared as a string with the value each leaving connection is labelled with, so `false` follows the connection labelled `false`. Returning `nil` follows the first connection. A route that returns `true` or `false` declares `output :result, type: :boolean, values: [true, false]`.
102
- 6. For a type that awaits input, write the partial named in `drawn_by`, for example `app/views/flow_steps/_rating.html.erb`. It receives the display object as `step`. It renders only the input, since the page supplies the form, the Next button and the Back button. The input must be named `answers[<step id>]`, or the answer is not recorded:
105
+ 7. For a type that awaits input, write the partial named in `drawn_by`, for example `app/views/flow_steps/_rating.html.erb`. It receives the display object as `step`. It renders only the input, since the page supplies the form, the Next button and the Back button. The input must be named `answers[<step id>]`, or the answer is not recorded:
103
106
 
104
107
  ```erb
105
108
  <%= label_tag "answers[#{step.id}]", step.text %>
@@ -116,7 +119,31 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
116
119
  setting :required, type: :boolean
117
120
  answer_check { |node, value| "Fill this in to go on." if node.config["required"] && value.blank? }
118
121
  ```
119
- 7. Restart the server, open a flow on the canvas and check the type is offered, its settings show, and a preview walks through it.
122
+ 8. For a type that waits, declare `waits_until` with a block that says whether what the step waits for has happened:
123
+
124
+ ```ruby
125
+ module FlowSteps
126
+ class AwaitPayment
127
+ include EasyFlow::Step
128
+
129
+ step_name "Payment"
130
+
131
+ setting :invoice_step, type: :previous_step
132
+
133
+ waits_until { |node, state| Invoice.paid?(state[node.config["invoice_step"]]) }
134
+ end
135
+ end
136
+ ```
137
+
138
+ - The block is given `node` and `state` only, the same as `process`, and is not given the run or its owner. Ask the developer what the step waits for, and how the block finds it from the step's settings and the answers recorded before it. If it cannot be found from those, stop and ask, since the block has nothing else to read.
139
+ - The block is called each time the visitor loads the step page, and each time the app calls `run.advance`. Keep it to a single lookup.
140
+ - While the block returns a falsy value, the visitor is shown `Waiting for <name>.` and no form, no Next button and no Back button. `<name>` is what `names_by` gives, or the `step_name` when there is none, so give the type a name a visitor can read.
141
+ - Once the block returns a truthy value, `true` is recorded under the step's id, or the value `process` returns when the type also defines `process`, and the run goes on to the next step.
142
+ - Do not declare `awaits_input` on a type that waits. The waiting message replaces the form, so the input is never shown.
143
+ - The page does not reload itself. Ask the developer how the run should move on when what it waits for happens:
144
+ - The visitor reloads the page. This needs nothing more, and works whether or not the flow keeps a stored run.
145
+ - The app calls `run.advance` where the event is handled, such as a webhook or a job. See "Read a run and its answers". This needs a stored run, so it only applies to a flow the admin set to save each step.
146
+ 9. Restart the server, open a flow on the canvas of each host that should offer the type, and check the type is in the palette, its settings show, and a preview walks through it. On a host that names a list of offered step types without the type's id, check the type is not in the palette.
120
147
 
121
148
  ### Serve a host's flows from the app's own controller
122
149
 
@@ -162,6 +189,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
162
189
  - `run.owner` — the optional record the run belongs to, polymorphic, set by the app. `run.label` and `run.status` are free string columns for the app's own use.
163
190
  - `run.pinned_definition` — the flow document of the version the run started on.
164
191
  - `run.next_step(answers)` and `run.walked(answers)` — the next step, and the answers on the path taken, for a set of answers against that pinned version.
192
+ - `run.advance` — moves the run past every waiting step whose `waits_until` block now returns a truthy value, and past every step that computes a value, and records each result on the run. It stops at the next step that asks the visitor for input, the next waiting step that is not ready, or the end. It does not call `finished`; that is called the next time the visitor loads the run's page.
165
193
  3. To show answers with their question text and answer labels, build a runner from the run's pinned document:
166
194
 
167
195
  ```ruby
@@ -181,11 +209,16 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
181
209
  - A step type's id comes from its class name or the id passed to `EasyFlow.step`, and it is stored in flow documents, so renaming the class or id breaks every flow that uses it.
182
210
  - Never give a step type one of the built-in ids: `start`, `terminal`, `question`, `condition`, `switch`, `compare`.
183
211
  - Register class-based step types inside `to_prepare`. A type registered anywhere else is lost on code reload in development.
212
+ - Registering a type does not put it in the palette of a host that names a list of offered step types without the type's id. Which step types a host offers is set through `easy_flow-install`, not here.
213
+ - A type that declares `ends_here` is in every host's palette, and a type that declares `begins_here` is in no host's palette.
184
214
  - An `options:` lambda is passed nothing, and one list is offered on every host's canvas, so it cannot narrow the options by admin, account or host.
185
215
  - A type that routes declares the values its output takes, or the canvas offers no connections to label.
186
216
  - 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.
187
217
  - Always look flows and runs up through a host.
188
218
  - A step's input field is named `answers[<step id>]` and submits one value. Any other name is ignored, and an array or hash is treated as blank.
189
219
  - An answer the type's `answer_check` refuses is never recorded, and the visitor is shown the same step with the check's message. An answer no check refuses is recorded, a blank one as `""`.
220
+ - A `waits_until` block is given only the step and the answers recorded so far, so what it waits for must be findable from those.
221
+ - A type that waits never also declares `awaits_input`.
222
+ - `run.advance` only moves a stored run, and never finishes it; the visitor's next page load does.
190
223
  - A `FlowsController` subclass needs all four named routes for its prefix; a missing one raises when the visitor is linked or redirected to it.
191
- - The engine installs, mounts and configures hosts, layouts, the default drawing and checks through `easy_flow-install`, not here.
224
+ - The engine installs, mounts and configures hosts, the step types each host offers, layouts, the default drawing and checks through `easy_flow-install`, not here.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-info
3
- description: Use to learn what easy_flow offers — guided flows an admin draws on a canvas and a visitor runs one step at a time, versioned documents of steps and connections, hosts, runs, the built-in step types including questions that can require an answer and branching on an answer or comparing a number, step types the host app registers and the checks they make on an answer, and the settings an admin fills in, including picks whose options come from the app's data.
3
+ description: Use to learn what easy_flow offers — guided flows an admin draws on a canvas and a visitor runs one step at a time, versioned documents of steps and connections, hosts and the step types each offers its admins, runs, the built-in step types including questions that can require an answer and branching on an answer or comparing a number, step types the host app registers, the checks they make on an answer, and steps that hold a run until something outside the flow has happened, and the settings an admin fills in, including picks whose options come from the app's data.
4
4
  tools: Read
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -11,19 +11,19 @@ This local explains easy_flow and the words it uses. It makes no changes and giv
11
11
 
12
12
  easy_flow is a Rails engine for guided, branching flows. An admin builds a flow on a canvas by placing steps and connecting them, previews it, and publishes it. A visitor then walks the published flow one step at a time, and each answer decides which step comes next.
13
13
 
14
- Reach for it when an app needs a questionnaire, an intake form, or any decision path that an admin should be able to change without a deploy. The engine ships a start step, an end step, a question step, and three steps that pick a branch from earlier answers. Anything else a flow needs to ask or do is a step type the app declares itself.
14
+ Reach for it when an app needs a questionnaire, an intake form, or any decision path that an admin should be able to change without a deploy. The engine ships a start step, an end step, a question step, and three steps that pick a branch from earlier answers. Anything else a flow needs to ask, do, or wait for is a step type the app declares itself.
15
15
 
16
16
  ## Interface
17
17
 
18
18
  easy_flow declares no commands of its own for this local. Its surface is split between the other two:
19
19
 
20
- - **easy_flow-install** owns putting the engine into an app: its migrations, mounting it, choosing the controller it inherits from, naming hosts, choosing the default step drawing, the flow checks, and the admin pages.
21
- - **easy_flow-develop** owns building on it: declaring and registering step types, serving a host's flows from the app's own controllers and routes, and reading a visitor's run and answers.
20
+ - **easy_flow-install** owns putting the engine into an app: its migrations, mounting it, choosing the controller it inherits from, naming hosts and the step types each one offers, choosing the default step drawing, the flow checks, and the admin pages.
21
+ - **easy_flow-develop** owns building on it: declaring and registering step types, including ones that wait, moving a run on once what it waits for has happened, serving a host's flows from the app's own controllers and routes, and reading a visitor's run and answers.
22
22
 
23
23
  ## How to use it
24
24
 
25
- - To get easy_flow running in an app, or to change how it is configured, use **easy_flow-install**.
26
- - To add a step type, give a step type its own rule for refusing an answer, put a flow on the app's own pages, or act on what a visitor answered, use **easy_flow-develop**.
25
+ - To get easy_flow running in an app, or to change how it is configured, including which step types a host's admins can add, use **easy_flow-install**.
26
+ - To add a step type, give a step type its own rule for refusing an answer, hold a run until something outside the flow has happened, put a flow on the app's own pages, or act on what a visitor answered, use **easy_flow-develop**.
27
27
  - To branch a flow on an answer or on a number the visitor gave, no code is needed: an admin places one of the built-in branching steps on the canvas.
28
28
  - To make a visitor answer a question before going on, no code is needed: an admin marks that question step as required on the canvas.
29
29
  - If the question is only what a word below means, this page is the answer.
@@ -35,7 +35,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
35
35
  - **Version** — a numbered snapshot of the document. A version is a draft until it is published, and a flow has at most one live version at a time.
36
36
  - **Canvas** — the admin screen where steps are added, configured, moved, removed and connected, with undo and redo. Publishing happens there.
37
37
  - **Preview** — an admin walking the current flow without starting a stored run.
38
- - **Step type** — what a kind of step is: its display name, its settings (the fields an admin fills in), its outputs (the values it records), and whether it waits for the visitor or acts on its own. A step that acts on its own may record a value worked out from the answers so far, pick which connection to follow, or both.
38
+ - **Step type** — what a kind of step is: its display name, its settings (the fields an admin fills in), its outputs (the values it records), and whether it waits for the visitor, acts on its own, or waits for something outside the flow. A step that acts on its own may record a value worked out from the answers so far, pick which connection to follow, or both.
39
39
  - **Answer check** — a rule a step type may carry that looks at a visitor's answer and, when the answer is not acceptable, returns the message the visitor sees. A step type with no such rule accepts every answer.
40
40
  - **Setting** — one field an admin fills in when configuring a step on the canvas. It is text, a whole number, a decimal, a yes or no, a pick from a list, several picks from a list, an earlier step, an earlier step's output, or a list of entries that each hold their own fields. A setting can be required, limited to a number of picks, or checked by a rule the step type supplies.
41
41
  - **Options** — the values a pick-from-a-list setting offers. They are either a fixed list written into the step type, or a lookup the app provides that is read each time the canvas or a save asks for them, so they can come from the app's own data. A saved value that is not among the options is refused.
@@ -46,8 +46,11 @@ easy_flow declares no commands of its own for this local. Its surface is split b
46
46
  - **Condition** — a built-in branching step that checks whether an earlier step's answer is, or is not, a chosen value, and follows the true or the false connection.
47
47
  - **Switch** — a built-in branching step that follows the connection labelled with an earlier step's answer.
48
48
  - **Compare** — a built-in branching step that reads an earlier step's answer as a number and checks it against an amount by more than, less than, at least or at most, then follows the true or the false connection. When the earlier step recorded several outputs, the admin picks which one. An answer that is missing or is not a number decides false.
49
+ - **Waiting step** — a step whose type carries a rule saying whether what it waits for has happened, such as a payment clearing or a document being signed. A run that reaches it stops there, and the visitor sees "Waiting for" followed by the step's name, with no form to submit. Once the rule says it has happened, the run moves past the step the next time the visitor's page is loaded or the app moves the run on, and the step is recorded as `true`.
49
50
  - **Registry** — the list of step types the app has registered, alongside the built-in ones. A step whose type is not registered is not shown or run as that type, and its answers are not checked.
50
- - **Host** — a named part of the app that owns a set of flows. A host sets the visitor layout and the admin layout, how admins are authenticated, how visitors are authorized, and how a refusal is answered. Flows are always looked up through a host, so one host never sees another's flows.
51
+ - **Host** — a named part of the app that owns a set of flows. A host sets the visitor layout and the admin layout, how admins are authenticated, how visitors are authorized, how a refusal is answered, and optionally which step types it offers. Flows are always looked up through a host, so one host never sees another's flows.
52
+ - **Offered step types** — the list of step types a host names for its admins to add. A host that names no list offers every registered step type. The list only narrows the palette.
53
+ - **Palette** — the step types an admin can add on a host's canvas. It never holds the start step, always holds the end step, and otherwise holds the step types the host offers. A step already in a flow whose type the host does not offer is still drawn and run.
51
54
  - **Run** — one visitor's pass through a flow. A run is pinned to the version that was live when it started, so publishing a new version does not change a run already under way. It records each answer by step id, and going back discards the last answer on the path.
52
55
  - **Answers** — the recorded state of a run, keyed by step id. The next step is always worked out from these answers and the connections in the pinned version.
53
56
  - **Refused answer** — an answer the step's answer check turned down. Nothing is recorded for that step, and the visitor is shown the same step again with the check's message. This works the same whether the flow keeps a stored run or carries its answers in the page.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-install
3
- description: Use to hook easy_flow into a project — copying and running its migrations, mounting the engine for each host, setting the controller it inherits from, declaring hosts with their layouts and access methods, choosing the default step drawing, turning on optional checks, and reaching the admin pages.
3
+ description: Use to hook easy_flow into a project — copying and running its migrations, mounting the engine for each host, setting the controller it inherits from, declaring hosts with their layouts, access methods and the step types each offers, choosing the default step drawing, turning on optional checks, and reaching the admin pages.
4
4
  tools: Bash, Read, Edit
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -16,7 +16,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
16
16
  - `bin/rails easy_flow:install:migrations` — copies the engine's migrations into the host's `db/migrate`, creating the flow, version and run tables.
17
17
  - `mount EasyFlow::Engine` — the route that serves one host's visitor pages and admin pages under a path, with the host named in `defaults: { easy_flow_host: "<host>" }`.
18
18
  - `EasyFlow.base_controller=` — the name, as a string, of the host controller every engine controller inherits from. Defaults to `"ActionController::Base"`.
19
- - `EasyFlow.host` — declares a named host with its visitor layout, admin layout, admin authentication method, visitor authorization method and refusal method.
19
+ - `EasyFlow.host` — declares a named host with its visitor layout, admin layout, admin authentication method, visitor authorization method, refusal method, and the step types its admins can add on the canvas.
20
20
  - `EasyFlow.draws_with` — the partial that draws a visitor's step when the step's type names none. Defaults to the engine's own `easy_flow/steps/choosing`.
21
21
  - `EasyFlow.check` — turns on an optional flow check: `:unrouted_value`, `:unfollowed_path` or `:dead_end`.
22
22
  - `/manage/flows` — the admin pages, under each mount path, where flows are listed, created, drawn on the canvas, previewed and published.
@@ -42,6 +42,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
42
42
  host.admin_authentication_method = :authenticate_admin!
43
43
  host.visitor_authorization_method = :easy_flow_visitor_permitted?
44
44
  host.refusal_method = :refuse_flow
45
+ host.offers = %i[question condition switch compare]
45
46
  end
46
47
  ```
47
48
 
@@ -50,6 +51,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
50
51
  - `admin_authentication_method` — a method on the base controller, called with no arguments before every admin page. With none set, the admin pages are open to anyone.
51
52
  - `visitor_authorization_method` — a method on the base controller, called with the flow, returning true when the visitor may run it. With none set, every visitor is refused.
52
53
  - `refusal_method` — a method on the base controller, called with the refusal error when a visitor is refused or a flow is unpublished or withdrawn. With none set, the response is `404 Not Found`.
54
+ - `offers` — the step types this host's admins can add from the canvas palette, as a list of step type names. With none set, every registered step type is offered. The engine's own names are `question`, `condition`, `switch` and `compare`, A step type the app declares is named by the id passed to `EasyFlow.step`, or after its class when it is a step class, so `Steps::Notify` is `notify`. The End step is offered whether it is listed or not, and the Start step is never offered. Ask the developer which step types each host should offer.
53
55
 
54
56
  Each method named here must exist on the base controller. Ask the developer to point at it or write it. Do not invent its logic.
55
57
  7. Mount the engine in `config/routes.rb`, once per host. The host name in `defaults` must match a name declared in step 6. When there is more than one mount, give each an `as:` name:
@@ -60,7 +62,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
60
62
  ```
61
63
 
62
64
  A mount whose host name is not declared serves no flows, and its admin pages return `404 Not Found`.
63
- 8. Ask the developer whether visitors' steps should be drawn with the engine's own partial or with one from the app. For the app's own, create a partial, for example `app/views/steps/_step.html.erb`, which receives the step as the local `step`. Then add to the initializer:
65
+ 8. Ask the developer whether visitors' steps should be drawn with the engine's own partial or with one from the app. For the app's own, create a partial, for example `app/views/steps/_step.html.erb`, which receives the step as the local `step`. It is rendered inside the engine's form, so it draws only the fields, and the visitor's answer must be submitted as `answers[<%= step.id %>]`. Then add to the initializer:
64
66
 
65
67
  ```ruby
66
68
  EasyFlow.draws_with("steps/step")
@@ -74,5 +76,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
74
76
  - After install, check that `<mount path>/manage/flows` shows the flow list and that a new flow opens on the canvas. If the canvas is blank, check that the admin layout calls `yield :head`.
75
77
  - After publishing a flow, check that `<mount path>/<slug>` shows it to a visitor who passes the host's visitor authorization method.
76
78
  - After upgrading easy_flow, run `bin/rails easy_flow:install:migrations` again and then `bin/rails db:migrate`. Only migrations the app does not already have are copied.
79
+ - After setting a host's `offers`, check that the canvas palette on that host's `<mount path>/manage/flows` lists only those step types and End.
80
+ - Taking a step type off a host's `offers` removes it from the palette only. Steps of that type already in the host's flows stay in them and keep running.
77
81
  - The initializer runs once at boot, so a change to it needs a server restart.
78
82
  - Declaring step types, serving a host's flows from the app's own controllers and routes, and reading runs and answers are out of scope here. They belong to the `easy_flow-develop` local.
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.4.7
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider