workflow 3.0.0 → 3.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +68 -44
- data/lib/workflow/event.rb +13 -3
- data/lib/workflow/event_collection.rb +2 -2
- data/lib/workflow/specification.rb +4 -0
- data/lib/workflow/version.rb +1 -1
- data/lib/workflow.rb +3 -3
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecf93e8750c9a77e512c840987b34f0616fd6304ed9f2bc98372aaea992fcfe9
|
4
|
+
data.tar.gz: 5e86611e43d7d49f61e814e3c6804664b2134c293c768ccb73ebd8bcb09b07c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e77f206fc4206d3407e33b3d044b5c291784a4f544bc01a21aacc3f8f92db0fa011a02acfe0987b352e01ddf7b391337ae3a4bde8616d44dfa331c48cfa86595
|
7
|
+
data.tar.gz: 33042e85d5f98fbef4c43094da563fb7b22fa2d175220489a062a0295ed52dc2f1445ecc941ce8094c0b858c468431458fadb73f80ec7c56c2b53c813310f260
|
data/README.adoc
CHANGED
@@ -102,7 +102,7 @@ article.current_state.between? :awaiting_review, :rejected # => true
|
|
102
102
|
```
|
103
103
|
|
104
104
|
Now we can call the submit event, which transitions to the
|
105
|
-
|
105
|
+
`:awaiting_review` state:
|
106
106
|
|
107
107
|
```rb
|
108
108
|
article.submit!
|
@@ -131,7 +131,7 @@ gem install workflow
|
|
131
131
|
install the `activesupport` and `ruby-graphviz` gems.
|
132
132
|
|
133
133
|
Versions up to and including 1.0.0 are also available as a single file download -
|
134
|
-
|
134
|
+
link:https://github.com/geekq/workflow/blob/v1.0.0/lib/workflow.rb[lib/workflow.rb file].
|
135
135
|
|
136
136
|
|
137
137
|
=== Examples
|
@@ -345,43 +345,6 @@ favorite database.
|
|
345
345
|
Advanced usage
|
346
346
|
--------------
|
347
347
|
|
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
|
-
|
385
348
|
### Conditional event transitions
|
386
349
|
|
387
350
|
Conditions can be a "method name symbol" with a corresponding instance method, a `proc` or `lambda` which are added to events, like so:
|
@@ -407,6 +370,8 @@ When calling a `device.can_<fire_event>?` check, or attempting a `device.<event>
|
|
407
370
|
* If an `:if` check is present, proceed if it evaluates to true, or drop to the next event.
|
408
371
|
* If you've run out of events to check (eg. `battery_level == 0`), then the transition isn't possible.
|
409
372
|
|
373
|
+
You can also pass additional arguments, which can be evaluated by :if methods or procs. See examples in
|
374
|
+
link:test/conditionals_test.rb#L45[conditionals_test.rb]
|
410
375
|
|
411
376
|
### Advanced transition hooks
|
412
377
|
|
@@ -487,11 +452,60 @@ The whole event sequence is as follows:
|
|
487
452
|
* event specific action
|
488
453
|
* on_transition (if action did not halt)
|
489
454
|
* on_exit
|
490
|
-
* PERSIST WORKFLOW STATE
|
455
|
+
* PERSIST WORKFLOW STATE (i.e. transition) or on_error
|
491
456
|
* on_entry
|
492
457
|
* after_transition
|
493
458
|
|
494
459
|
|
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
|
+
### Defining workflow dynamically from JSON
|
498
|
+
|
499
|
+
For an advance example please see
|
500
|
+
link:https://github.com/geekq/workflow/blob/develop/test/workflow_from_json_test.rb[workflow_from_json_test.rb].
|
501
|
+
|
502
|
+
|
503
|
+
### Compose workflow definition with `include`
|
504
|
+
|
505
|
+
In case you have very extensive workflow definition or would like to reuse
|
506
|
+
workflow definition for different classes, you can include parts like in
|
507
|
+
the link:https://github.com/geekq/workflow/blob/develop/test/main_test.rb#L95-L110[`including a child workflow definition` example].
|
508
|
+
|
495
509
|
Documenting with diagrams
|
496
510
|
-------------------------
|
497
511
|
|
@@ -513,11 +527,17 @@ end
|
|
513
527
|
Changelog
|
514
528
|
---------
|
515
529
|
|
530
|
+
=== New in the version 3.1.0
|
531
|
+
|
532
|
+
* link:https://github.com/geekq/workflow/pull/227[#227] Allow event arguments to be taken into account when selecting the event
|
533
|
+
* link:https://github.com/geekq/workflow/pull/232[#232] Add ability to include partial workflow definitions for composability
|
534
|
+
* link:https://github.com/geekq/workflow/pull/241[#241] Example for defining workflow dynamically from JSON
|
535
|
+
|
516
536
|
=== New in the version 3.0.0
|
517
537
|
|
518
|
-
*
|
538
|
+
* link:https://github.com/geekq/workflow/pull/228[#228] Support for Ruby 3 keyword args, provided by @agirling
|
519
539
|
* retire Ruby 2.6 since it has reached end of live; please use workflow 2.x, if you still depend on that Ruby version
|
520
|
-
*
|
540
|
+
* link:https://github.com/geekq/workflow/pull/229[#229] Switch from travis CI to GihHub actions for continuous integration
|
521
541
|
|
522
542
|
### New in the versions 2.x
|
523
543
|
|
@@ -543,6 +563,11 @@ bundle install
|
|
543
563
|
bundle exec rake test
|
544
564
|
```
|
545
565
|
|
566
|
+
### Check list for you pull request
|
567
|
+
|
568
|
+
* [ ] unit tests for the new behavior provided: new tests fail without you change, all tests succeed with your change
|
569
|
+
* [ ] documentation update included
|
570
|
+
|
546
571
|
### Other 3rd party libraries
|
547
572
|
|
548
573
|
https://github.com/kwent/active_admin-workflow[ActiveAdmin-Workflow] - is an
|
@@ -552,7 +577,7 @@ integration with https://github.com/activeadmin/activeadmin[ActiveAdmin].
|
|
552
577
|
|
553
578
|
Author: Vladimir Dobriakov, <https://infrastructure-as-code.de>
|
554
579
|
|
555
|
-
Copyright (c) 2010-
|
580
|
+
Copyright (c) 2010-2024 Vladimir Dobriakov and Contributors
|
556
581
|
|
557
582
|
Copyright (c) 2008-2009 Vodafone
|
558
583
|
|
@@ -561,4 +586,3 @@ Copyright (c) 2007-2008 Ryan Allen, FlashDen Pty Ltd
|
|
561
586
|
Based on the work of Ryan Allen and Scott Barron
|
562
587
|
|
563
588
|
Licensed under MIT license, see the MIT-LICENSE file.
|
564
|
-
|
data/lib/workflow/event.rb
CHANGED
@@ -15,12 +15,22 @@ module Workflow
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def condition_applicable?(object)
|
18
|
+
def condition_applicable?(object, event_arguments)
|
19
19
|
if condition
|
20
20
|
if condition.is_a?(Symbol)
|
21
|
-
object.
|
21
|
+
m = object.method(condition)
|
22
|
+
# Conditionals can now take the arguments of the trasition action into account #227
|
23
|
+
# But in case the current conditional wants to ignore any event_argument on its decision -
|
24
|
+
# does not accept parameters, also support that.
|
25
|
+
if m.arity == 0 # no additional parameters accepted
|
26
|
+
object.send(condition)
|
27
|
+
else
|
28
|
+
object.send(condition, *event_arguments)
|
29
|
+
end
|
22
30
|
else
|
23
|
-
|
31
|
+
# since blocks can ignore extra arguments without raising an error in Ruby,
|
32
|
+
# no `if` is needed - compare with `arity` switch in above methods handling
|
33
|
+
condition.call(object, *event_arguments)
|
24
34
|
end
|
25
35
|
else
|
26
36
|
true
|
@@ -26,9 +26,9 @@ module Workflow
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def first_applicable(name, object_context)
|
29
|
+
def first_applicable(name, object_context, event_arguments)
|
30
30
|
(self[name] || []).detect do |event|
|
31
|
-
event.condition_applicable?(object_context) && event
|
31
|
+
event.condition_applicable?(object_context, event_arguments) && event
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -20,6 +20,10 @@ module Workflow
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
+
def include(proc)
|
24
|
+
instance_eval(&proc)
|
25
|
+
end
|
26
|
+
|
23
27
|
def state(name, meta = {:meta => {}}, &events_and_etc)
|
24
28
|
# meta[:meta] to keep the API consistent..., gah
|
25
29
|
new_state = Workflow::State.new(name, self, meta[:meta])
|
data/lib/workflow/version.rb
CHANGED
data/lib/workflow.rb
CHANGED
@@ -65,8 +65,8 @@ module Workflow
|
|
65
65
|
process_event!(event_name, *args, **kwargs)
|
66
66
|
end
|
67
67
|
|
68
|
-
define_method "can_#{event_name}?" do
|
69
|
-
return !!current_state.events.first_applicable(event_name, self)
|
68
|
+
define_method "can_#{event_name}?".to_sym do |*args, **kwargs|
|
69
|
+
return !!current_state.events.first_applicable(event_name, self, args)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -95,7 +95,7 @@ module Workflow
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def process_event!(name, *args, **kwargs)
|
98
|
-
event = current_state.events.first_applicable(name, self)
|
98
|
+
event = current_state.events.first_applicable(name, self, args)
|
99
99
|
raise NoTransitionAllowed.new(
|
100
100
|
"There is no event #{name.to_sym} defined for the #{current_state} state") \
|
101
101
|
if event.nil?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.1.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dobriakov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '6.
|
19
|
+
version: '6.4'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '6.
|
26
|
+
version: '6.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2.
|
33
|
+
version: '2.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2.
|
40
|
+
version: '2.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mocha
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '5.
|
75
|
+
version: '5.21'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '5.
|
82
|
+
version: '5.21'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: ruby-graphviz
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,7 @@ homepage: https://github.com/geekq/workflow
|
|
122
122
|
licenses:
|
123
123
|
- MIT
|
124
124
|
metadata: {}
|
125
|
-
post_install_message:
|
125
|
+
post_install_message:
|
126
126
|
rdoc_options: []
|
127
127
|
require_paths:
|
128
128
|
- lib
|
@@ -133,12 +133,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '2.7'
|
134
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - ">"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
138
|
+
version: 1.3.1
|
139
139
|
requirements: []
|
140
|
-
rubygems_version: 3.
|
141
|
-
signing_key:
|
140
|
+
rubygems_version: 3.3.7
|
141
|
+
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: A replacement for acts_as_state_machine.
|
144
144
|
test_files: []
|