Skip to content

Commit 62eea71

Browse files
committed
Add step display to README
1 parent 812350c commit 62eea71

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ decision. When called, the decision macro will invoke this method, then
2828
act according to the truthiness of the response returned - invoking the
2929
code in its `yes` block for true, and `no` block for false.
3030

31-
To accomodate interruptions to the decision tree, perhaps at locations where
31+
To accommodate interruptions to the decision tree, perhaps at locations where
3232
user input is required, the `entry` macro can be used to define new entry
3333
points. This macro takes the name of the entry point, and can be invoked by
3434
calling this method from outside the workflow class.
@@ -90,6 +90,56 @@ class Change < ActiveRecord::Base
9090
end
9191
```
9292

93+
##Displaying the Workflow
94+
Human readable display of workflow steps can be achieved by using `DecisionTree::Step#display`.
95+
E.g.
96+
97+
```ruby
98+
- workflow.steps.each do |step|
99+
= step.display
100+
```
101+
102+
The value returned by this will either be one set explicitly in the translations, or one implicitly derived from the step name.
103+
104+
105+
### Explicit Display Values
106+
Human readable translations are defined under `workflow_steps`.
107+
108+
E.g.:
109+
110+
workflow_steps:
111+
entry_point:
112+
__start_workflow: 'Decision Workflow Started'
113+
reviewed_by_etd!: 'ETD has reviewed the provided evidence'
114+
idempotent_call:
115+
mark_for_review!: 'Waiting on ETD to review evidence'
116+
approval_only_required_from_initiator?:
117+
'yes': 'Approval is only required from the initiator'
118+
'no': 'This change must be approved by more than the initiator'
119+
120+
Any entry point into the workflow is defined under `entry_point`, including the initial one that is automatically created by the gem (`__start_workflow`).
121+
Any idempotent calls (identified by a trailing `!`) are defined under `idempotent_call`.
122+
123+
Any regular steps (with a yes/no outcome) are defined directly under `workflow_steps`, and contain values for both 'yes', and 'no'. Note that these keys should be defined as strings (explicitly wrapped in quotes), otherwise YAML helpfully converts these to booleans, which will not be matched when looking for a description.
124+
125+
### Implicit Display Values
126+
Semi-friendly display values are still returned if no translation has been defined.
127+
For a regular step, the question will be rendered, followed by the answer.
128+
129+
```
130+
# method name: is_contract_full_time?
131+
# answer is 'NO'
132+
step.display # => Is contract full time? - No
133+
134+
```
135+
136+
Entry points and idempotent calls are also slightly humanised.
137+
138+
```
139+
:reviewed_by_etd! # => Reviewed by etd!
140+
```
141+
142+
93143
## Contributing
94144

95145
1. Fork it ( http://github.com/jobready/decision_tree/fork )

0 commit comments

Comments
 (0)