finist 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/README.md +35 -6
- data/finist.gemspec +1 -1
- data/lib/finist.rb +1 -6
- data/test/all.rb +9 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bbf0d801dbbcdedc3e1ce1ce672229c2f3b9a8a
|
4
|
+
data.tar.gz: b93e52acbe5feb52b6ea4a784c073faf1c0377f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c78ebef60005b2f8696fd3f97284e00064daf4c961f4f312a62b7bca213dea74438a50b9454d21336b3799e8295a22d3546c4c8d28a92bc19280228bbb1436e6
|
7
|
+
data.tar.gz: 7d3674cea94bf30a3e2fa1471a7c84fb7eb7d7fe92ccf47d71a497a82f1c1c746318fa0437d09e3d060df81fee970e2bf78448d479a1e6947d327d09bc5e9ae3
|
data/CHANGELOG
ADDED
data/README.md
CHANGED
@@ -18,7 +18,8 @@ Meet us on IRC: [#lesscode](irc://chat.freenode.net/#lesscode) on
|
|
18
18
|
Related projects
|
19
19
|
----------------
|
20
20
|
|
21
|
-
|
21
|
+
* [Finist implemented in Lua][finist.lua]
|
22
|
+
* [Finist implemented in Rust][finist.rust]
|
22
23
|
|
23
24
|
Getting started
|
24
25
|
---------------
|
@@ -67,24 +68,24 @@ And we can trigger an event:
|
|
67
68
|
|
68
69
|
```ruby
|
69
70
|
machine.trigger("approve")
|
70
|
-
# => [
|
71
|
+
# => ["approved", true]
|
71
72
|
```
|
72
73
|
|
73
74
|
The `trigger` method returns an array of two values: the first
|
74
|
-
represents
|
75
|
-
|
75
|
+
represents the current state, and the second represents whether
|
76
|
+
a transition occurred.
|
76
77
|
|
77
78
|
Here's what happens if an event doesn't cause a transition:
|
78
79
|
|
79
80
|
```ruby
|
80
81
|
machine.trigger("reset")
|
81
|
-
# => [
|
82
|
+
# => ["approved", false]
|
82
83
|
```
|
83
84
|
|
84
85
|
Here's a convenient way to use this flag:
|
85
86
|
|
86
87
|
```ruby
|
87
|
-
|
88
|
+
state, changed = machine.trigger("reset")
|
88
89
|
|
89
90
|
if changed
|
90
91
|
printf("State changed to %s\n", state)
|
@@ -100,6 +101,33 @@ machine.rm("reset")
|
|
100
101
|
|
101
102
|
Note that every change is persisted in Redis.
|
102
103
|
|
104
|
+
Representation
|
105
|
+
--------------
|
106
|
+
|
107
|
+
Each event is represented as a hash in Redis, and its field/value
|
108
|
+
pairs are the possible transitions.
|
109
|
+
|
110
|
+
For the FSM described in the examples above, the keys are laid out
|
111
|
+
as follows:
|
112
|
+
|
113
|
+
```ini
|
114
|
+
# Current state
|
115
|
+
finist:order (string)
|
116
|
+
|
117
|
+
# Transitions for event `approve`
|
118
|
+
finist:order:approve (hash)
|
119
|
+
pending -> approved
|
120
|
+
|
121
|
+
# Transitions for event `cancel`
|
122
|
+
finist:order:cancel (hash)
|
123
|
+
pending -> cancelled
|
124
|
+
approved -> cancelled
|
125
|
+
|
126
|
+
# Transitions for event `reset`
|
127
|
+
finist:order:reset (hash)
|
128
|
+
cancelled -> pending
|
129
|
+
```
|
130
|
+
|
103
131
|
Installation
|
104
132
|
------------
|
105
133
|
|
@@ -110,3 +138,4 @@ $ gem install finist
|
|
110
138
|
[redis]: http://redis.io
|
111
139
|
[redic]: https://github.com/amakawa/redic
|
112
140
|
[finist.lua]: https://github.com/soveran/finist.lua
|
141
|
+
[finist.rust]: https://github.com/badboy/finist
|
data/finist.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "finist"
|
3
|
-
s.version = "0.0
|
3
|
+
s.version = "0.1.0"
|
4
4
|
s.summary = %{Redis based Finite State Machine}
|
5
5
|
s.description = %Q{Finist is a finite state machine that is defined and persisted in Redis.}
|
6
6
|
s.authors = ["Michel Martens"]
|
data/lib/finist.rb
CHANGED
data/test/all.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require_relative "helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
setup do
|
4
|
+
Redic.new.tap do |c|
|
5
|
+
c.call("FLUSHDB")
|
6
|
+
end
|
7
|
+
end
|
5
8
|
|
9
|
+
test do |c|
|
6
10
|
fsm = Finist.new(c, "myfsm", "pending")
|
7
11
|
|
8
12
|
fsm.on("approve", "pending", "approved")
|
@@ -38,13 +42,13 @@ test do
|
|
38
42
|
assert_equal("cancelled", fsm2.state)
|
39
43
|
|
40
44
|
# A successful event returns true
|
41
|
-
|
45
|
+
state, changed = fsm.trigger("reset")
|
42
46
|
|
43
47
|
assert_equal(true, changed)
|
44
48
|
assert_equal("pending", state)
|
45
49
|
|
46
50
|
# An unsuccessful event returns false
|
47
|
-
|
51
|
+
state, changed = fsm.trigger("reset")
|
48
52
|
|
49
53
|
assert_equal(false, changed)
|
50
54
|
assert_equal("pending", state)
|
@@ -53,7 +57,7 @@ test do
|
|
53
57
|
fsm.rm("approve")
|
54
58
|
|
55
59
|
# Non existent events return false
|
56
|
-
|
60
|
+
state, changed = fsm.trigger("approve")
|
57
61
|
|
58
62
|
assert_equal(false, changed)
|
59
63
|
assert_equal("pending", state)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redic
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- .gems
|
49
|
+
- CHANGELOG
|
49
50
|
- LICENSE
|
50
51
|
- README.md
|
51
52
|
- finist.gemspec
|