stateful.rb 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +62 -4
- data/lib/Stateful/VERSION.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 045517b47c6e558d4e414bc639973934c27abc955a5d6281088c3413c38e9a9b
|
|
4
|
+
data.tar.gz: db57952692bd309d8389c6d02de659c5dc3a0ab6ac361ecd491aeba5db3860e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ffcb05702b938f0f62d2d661adea0cdc64017eadcb3d6e328c369d88c8655f193ab58b2508706ed8ae3a7b71c0c09805a19bc8212493057b96a46d75e89fed5
|
|
7
|
+
data.tar.gz: bc0e1b4772f7e30f32df35542df5264c4ebe90c6d94ad52009362647f0c98a5450d9c9c303f5c87cfb0140ee03b7c81998ce492d19f85ed38e07ff3a3172772e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# stateful/CHANGELOG.md
|
|
2
2
|
|
|
3
|
+
## 2.3.2 (20260418): Add Sequel examples to README.
|
|
4
|
+
-----------------------------------------------------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
### ~
|
|
7
|
+
1. README.md: + Sequel examples (sections 5 and 6), updated description to include Sequel,
|
|
8
|
+
renumbered remaining sections.
|
|
9
|
+
2. lib/Stateful/VERSION.rb: /2.3.1/2.3.2/
|
|
10
|
+
|
|
11
|
+
|
|
3
12
|
## 2.3.1 (20260418): Use require\_relative in tests.
|
|
4
13
|
-----------------------------------------------------------------------------------------------------------------------
|
|
5
14
|
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
4
|
|
|
5
|
-
A Ruby state machine which allows you to easily add state to Poro and
|
|
5
|
+
A Ruby state machine which allows you to easily add state to Poro, ActiveRecord, and Sequel objects. Works with both CRuby and mRuby.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -149,9 +149,67 @@ active_record_machine.final_state?
|
|
|
149
149
|
# => true
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
### 5.
|
|
152
|
+
### 5. Sequel with persistence-specific extend and a stateful block declaration
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
```ruby
|
|
155
|
+
class SequelMachine < Sequel::Model
|
|
156
|
+
extend Stateful::Sequel
|
|
157
|
+
|
|
158
|
+
stateful do
|
|
159
|
+
initial_state :initial_state
|
|
160
|
+
|
|
161
|
+
state :initial_state do
|
|
162
|
+
on :an_event => :next_state
|
|
163
|
+
on :another_event => :final_state
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
state :next_state do
|
|
167
|
+
on :yet_another_event => :final_state
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
final_state :final_state
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
sequel_machine = SequelMachine.create
|
|
175
|
+
sequel_machine.initial_state?
|
|
176
|
+
# => true
|
|
177
|
+
sequel_machine.an_event
|
|
178
|
+
sequel_machine.next_state?
|
|
179
|
+
# => true
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 6. Sequel with persistence non-specific extend, without a stateful block declaration, an initial_state block, and multiple final states
|
|
183
|
+
|
|
184
|
+
```ruby
|
|
185
|
+
class SequelMachine < Sequel::Model
|
|
186
|
+
extend Stateful
|
|
187
|
+
|
|
188
|
+
initial_state :initial_state do
|
|
189
|
+
on :an_event => :next_state
|
|
190
|
+
on :another_event => :final_state0
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
state :next_state do
|
|
194
|
+
on :yet_another_event => :final_state0
|
|
195
|
+
on :and_yet_another_event => :final_state1
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
final_state :final_state0, :final_state1
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
sequel_machine = SequelMachine.create
|
|
202
|
+
sequel_machine.an_event
|
|
203
|
+
sequel_machine.final_state?
|
|
204
|
+
# => false
|
|
205
|
+
sequel_machine.yet_another_event
|
|
206
|
+
sequel_machine.final_state?
|
|
207
|
+
# => true
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### 7. Custom attribute name and non-deterministic event ordering
|
|
211
|
+
|
|
212
|
+
It's also possible to define a state machine which has a custom attribute name, which fires off the events in a random or non-deterministic order, and which has no final state.
|
|
155
213
|
|
|
156
214
|
```ruby
|
|
157
215
|
class ActiveRecordMachine < ActiveRecord::Base
|
|
@@ -285,7 +343,7 @@ class Order
|
|
|
285
343
|
end
|
|
286
344
|
```
|
|
287
345
|
|
|
288
|
-
For ActiveRecord, each machine uses a column named `<machine_name>_state`:
|
|
346
|
+
For ActiveRecord and Sequel, each machine uses a column named `<machine_name>_state`:
|
|
289
347
|
|
|
290
348
|
```ruby
|
|
291
349
|
class CreateOrders < ActiveRecord::Migration[6.0]
|
data/lib/Stateful/VERSION.rb
CHANGED