Skip to content

Commit 2529e30

Browse files
committed
Documentation for #232 include partial workflow definitions
1 parent d580508 commit 2529e30

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

README.adoc

+46-39
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ gem install workflow
131131
install the `activesupport` and `ruby-graphviz` gems.
132132
133133
Versions up to and including 1.0.0 are also available as a single file download -
134-
[lib/workflow.rb file](https://github.com/geekq/workflow/blob/v1.0.0/lib/workflow.rb).
134+
link:https://github.com/geekq/workflow/blob/v1.0.0/lib/workflow.rb[lib/workflow.rb file].
135135
136136
137137
=== Examples
@@ -345,43 +345,6 @@ favorite database.
345345
Advanced usage
346346
--------------
347347
348-
### Accessing your workflow specification
349-
350-
You can easily reflect on workflow specification programmatically - for
351-
the whole class or for the current object. Examples:
352-
353-
```rb
354-
article2.current_state.events # lists possible events from here
355-
article2.current_state.events[:reject].transitions_to # => :rejected
356-
357-
Article.workflow_spec.states.keys
358-
#=> [:rejected, :awaiting_review, :being_reviewed, :accepted, :new]
359-
360-
Article.workflow_spec.state_names
361-
#=> [:rejected, :awaiting_review, :being_reviewed, :accepted, :new]
362-
363-
# list all events for all states
364-
Article.workflow_spec.states.values.collect &:events
365-
```
366-
367-
You can also store and later retrieve additional meta data for every
368-
state and every event:
369-
370-
```rb
371-
class MyProcess
372-
include Workflow
373-
workflow do
374-
state :main, :meta => {:importance => 8}
375-
state :supplemental, :meta => {:importance => 1}
376-
end
377-
end
378-
puts MyProcess.workflow_spec.states[:supplemental].meta[:importance] # => 1
379-
```
380-
381-
The workflow library itself uses this feature to tweak the graphical
382-
representation of the workflow. See below.
383-
384-
385348
### Conditional event transitions
386349
387350
Conditions can be a "method name symbol" with a corresponding instance method, a `proc` or `lambda` which are added to events, like so:
@@ -494,6 +457,49 @@ The whole event sequence is as follows:
494457
* after_transition
495458
496459
460+
### Accessing your workflow specification
461+
462+
You can easily reflect on workflow specification programmatically - for
463+
the whole class or for the current object. Examples:
464+
465+
```rb
466+
article2.current_state.events # lists possible events from here
467+
article2.current_state.events[:reject].transitions_to # => :rejected
468+
469+
Article.workflow_spec.states.keys
470+
#=> [:rejected, :awaiting_review, :being_reviewed, :accepted, :new]
471+
472+
Article.workflow_spec.state_names
473+
#=> [:rejected, :awaiting_review, :being_reviewed, :accepted, :new]
474+
475+
# list all events for all states
476+
Article.workflow_spec.states.values.collect &:events
477+
```
478+
479+
You can also store and later retrieve additional meta data for every
480+
state and every event:
481+
482+
```rb
483+
class MyProcess
484+
include Workflow
485+
workflow do
486+
state :main, :meta => {:importance => 8}
487+
state :supplemental, :meta => {:importance => 1}
488+
end
489+
end
490+
puts MyProcess.workflow_spec.states[:supplemental].meta[:importance] # => 1
491+
```
492+
493+
The workflow library itself uses this feature to tweak the graphical
494+
representation of the workflow. See below.
495+
496+
497+
### Compose workflow definition with `include`
498+
499+
In case you have very extensive workflow definition or would like to reuse
500+
workflow definition for different classes, you can include parts like in
501+
the link:https://github.com/geekq/workflow/blob/develop/test/main_test.rb#L95-L110[`including a child workflow definition` example].
502+
497503
Documenting with diagrams
498504
-------------------------
499505

@@ -517,7 +523,8 @@ Changelog
517523
518524
=== New in the version 3.1.0
519525
520-
* link:https://github.com/geekq/workflow/pull/227[#227] allow event arguments to be taken into account when selecting the event
526+
* link:https://github.com/geekq/workflow/pull/227[#227] Allow event arguments to be taken into account when selecting the event
527+
* link:https://github.com/geekq/workflow/pull/232[#232] Add ability to include partial workflow definitions for composability
521528
522529
=== New in the version 3.0.0
523530

0 commit comments

Comments
 (0)