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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ef4a139c70308a595e49e7ba7053a64631c33e0
4
- data.tar.gz: 6a640ada556919739c4bc01de30d4aa3e9fba735
3
+ metadata.gz: 1bbf0d801dbbcdedc3e1ce1ce672229c2f3b9a8a
4
+ data.tar.gz: b93e52acbe5feb52b6ea4a784c073faf1c0377f1
5
5
  SHA512:
6
- metadata.gz: c5720d02f6093f0eeb9bd20161f7b7b617f70c20ded4a85d8305cb2f61e5e38c50e2b3c18ea33c225fb35841cc6d0f28b88bbe75dc5e409a4297698965bbbd11
7
- data.tar.gz: 2cc188dd3d8a6d7fd58bdab1c9727765ca7ddbb346132e687364617ece39a41d5127df78382838a4e333736cbe32241892c7fd4f4ece7f7cf75085a2cd2f6cae
6
+ metadata.gz: c78ebef60005b2f8696fd3f97284e00064daf4c961f4f312a62b7bca213dea74438a50b9454d21336b3799e8295a22d3546c4c8d28a92bc19280228bbb1436e6
7
+ data.tar.gz: 7d3674cea94bf30a3e2fa1471a7c84fb7eb7d7fe92ccf47d71a497a82f1c1c746318fa0437d09e3d060df81fee970e2bf78448d479a1e6947d327d09bc5e9ae3
@@ -0,0 +1,3 @@
1
+ 0.1.0
2
+
3
+ Change order of returned values.
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
- There's an [alternative implementation for Lua][finist.lua].
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
- # => [true, "approved"]
71
+ # => ["approved", true]
71
72
  ```
72
73
 
73
74
  The `trigger` method returns an array of two values: the first
74
- represents whether a transition occurred, and the second represents
75
- the current state.
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
- # => [false, "approved"]
82
+ # => ["approved", false]
82
83
  ```
83
84
 
84
85
  Here's a convenient way to use this flag:
85
86
 
86
87
  ```ruby
87
- changed, state = machine.trigger("reset")
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "finist"
3
- s.version = "0.0.1"
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"]
@@ -43,11 +43,6 @@ class Finist
43
43
 
44
44
  def trigger(ev)
45
45
  result = send_event(ev)
46
-
47
- if result[1]
48
- return true, result[0]
49
- else
50
- return false, result[0]
51
- end
46
+ return result[0], result[1] != nil
52
47
  end
53
48
  end
@@ -1,8 +1,12 @@
1
1
  require_relative "helper"
2
2
 
3
- test do
4
- c = Redic.new
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
- changed, state = fsm.trigger("reset")
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
- changed, state = fsm.trigger("reset")
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
- changed, state = fsm.trigger("approve")
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.1
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-02-03 00:00:00.000000000 Z
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