microfsm 0.1.6 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +22 -0
- data/README.md +3 -4
- data/lib/{version.rb → microfsm/version.rb} +3 -1
- metadata +12 -23
- data/.github/workflows/rake.yml +0 -26
- data/.gitignore +0 -11
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -56
- data/LICENSE +0 -21
- data/Rakefile +0 -10
- data/microfsm.gemspec +0 -21
- data/test/callbacks_test.rb +0 -35
- data/test/introspection_test.rb +0 -22
- data/test/microfsm_test.rb +0 -72
- data/test/test_helper.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d2e652821a740ba42ae709c3e978631c4a1467649e15b69aedaa07d257141f4
|
4
|
+
data.tar.gz: c333a20cee8e96dec737b822d6aa96909458a0f61801751d6c0857fa71ee87a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 577d4e3640dd78a8a8ee56f5a10c726c180a2e9d47d0775bb53162be29196cb88e37534189fd644e537e0f3da0fa11b93783e66fa08d5ab5298dc3d613748209
|
7
|
+
data.tar.gz: '0950e2d2b4dbf8733c24890e065e4d3ac4973b6fddd02e0b31e523215200d3caa81843a634070dc6f04e018dee58f1808b7882338d034f25f7fcb60fb9755bc3'
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021-2024 Dittmar Krall (www.matiq.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# MicroFSM
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/microfsm.svg)](https://badge.fury.io/rb/microfsm)
|
4
|
+
[![GEM Downloads](https://img.shields.io/gem/dt/microfsm?color=168AFE&logo=ruby&logoColor=FE1616)](https://rubygems.org/gems/microfsm)
|
4
5
|
|
5
6
|
MicroFSM implements a minimal/simple Finite-State Machine (FSM).
|
6
7
|
Transitions are triggered by events.
|
@@ -96,7 +97,7 @@ fsm.state = :new
|
|
96
97
|
fsm.state #=> :new
|
97
98
|
```
|
98
99
|
|
99
|
-
Check the
|
100
|
+
Check the _examples_ directory for more information.
|
100
101
|
|
101
102
|
## Links
|
102
103
|
|
@@ -106,6 +107,4 @@ Check the examples directory for more information.
|
|
106
107
|
## Miscellaneous
|
107
108
|
|
108
109
|
Copyright (c) 2021-2023 Dittmar Krall (www.matiq.com),
|
109
|
-
released under the MIT license
|
110
|
-
|
111
|
-
* https://opensource.org/licenses/MIT
|
110
|
+
released under the [MIT license](https://opensource.org/licenses/MIT).
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class MicroFSM
|
4
|
-
VERSION = "0.1.
|
4
|
+
VERSION = "0.1.9" # 2024-05-22
|
5
|
+
# VERSION = "0.1.7" # 2023-12-12
|
6
|
+
# VERSION = "0.1.6" # 2023-04-25
|
5
7
|
# VERSION = "0.1.5" # 2022-12-22
|
6
8
|
# VERSION = "0.1.3" # 2021-06-22
|
7
9
|
# VERSION = "0.1.2" # 2021-02-10
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: microfsm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -43,32 +43,21 @@ description: MicroFSM implements a minimal/simple Finite-State Machine (FSM). Tr
|
|
43
43
|
email: dittmar.krall@matiq.com
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
|
-
extra_rdoc_files:
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
- MIT-LICENSE
|
47
49
|
files:
|
48
|
-
-
|
49
|
-
- ".gitignore"
|
50
|
-
- ".ruby-gemset"
|
51
|
-
- ".ruby-version"
|
52
|
-
- Gemfile
|
53
|
-
- Gemfile.lock
|
54
|
-
- LICENSE
|
50
|
+
- MIT-LICENSE
|
55
51
|
- README.md
|
56
|
-
- Rakefile
|
57
52
|
- examples/advanced.rb
|
58
53
|
- examples/basic.rb
|
59
54
|
- examples/callbacks.rb
|
60
55
|
- lib/microfsm.rb
|
61
|
-
- lib/version.rb
|
62
|
-
|
63
|
-
- test/callbacks_test.rb
|
64
|
-
- test/introspection_test.rb
|
65
|
-
- test/microfsm_test.rb
|
66
|
-
- test/test_helper.rb
|
67
|
-
homepage: https://matiq.com
|
56
|
+
- lib/microfsm/version.rb
|
57
|
+
homepage: https://github.com/matique/microfsm
|
68
58
|
licenses:
|
69
59
|
- MIT
|
70
|
-
metadata:
|
71
|
-
source_code_uri: https://github.com/matique/microfsm
|
60
|
+
metadata: {}
|
72
61
|
post_install_message:
|
73
62
|
rdoc_options: []
|
74
63
|
require_paths:
|
@@ -84,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
73
|
- !ruby/object:Gem::Version
|
85
74
|
version: '0'
|
86
75
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.5.10
|
88
77
|
signing_key:
|
89
78
|
specification_version: 4
|
90
79
|
summary: Minimal Finite State Machine.
|
data/.github/workflows/rake.yml
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
|
2
|
-
name: Rake
|
3
|
-
|
4
|
-
on: [push]
|
5
|
-
|
6
|
-
jobs:
|
7
|
-
test:
|
8
|
-
strategy:
|
9
|
-
fail-fast: false
|
10
|
-
matrix:
|
11
|
-
os: [ubuntu-latest]
|
12
|
-
ruby: ["2.7", "3.0", "3.2", head]
|
13
|
-
test_command: ["bundle exec rake test"]
|
14
|
-
runs-on: ${{ matrix.os }}
|
15
|
-
|
16
|
-
steps:
|
17
|
-
- uses: actions/checkout@v3
|
18
|
-
- uses: ruby/setup-ruby@v1
|
19
|
-
with:
|
20
|
-
ruby-version: ${{ matrix.ruby }}
|
21
|
-
- name: Bundle install
|
22
|
-
run: |
|
23
|
-
bundle config path /home/runner/bundle
|
24
|
-
bundle install
|
25
|
-
bundle update
|
26
|
-
- run: ${{ matrix.test_command }}
|
data/.gitignore
DELETED
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rails-7.0
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-3.2.2
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
microfsm (0.1.6)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.2)
|
10
|
-
docile (1.4.0)
|
11
|
-
json (2.6.3)
|
12
|
-
minitest (5.18.0)
|
13
|
-
observr (1.0.5)
|
14
|
-
parallel (1.23.0)
|
15
|
-
parser (3.2.2.1)
|
16
|
-
ast (~> 2.4.1)
|
17
|
-
rainbow (3.1.1)
|
18
|
-
rake (13.0.6)
|
19
|
-
regexp_parser (2.8.0)
|
20
|
-
rexml (3.2.5)
|
21
|
-
ricecream (0.2.1)
|
22
|
-
rubocop (1.50.2)
|
23
|
-
json (~> 2.3)
|
24
|
-
parallel (~> 1.10)
|
25
|
-
parser (>= 3.2.0.0)
|
26
|
-
rainbow (>= 2.2.2, < 4.0)
|
27
|
-
regexp_parser (>= 1.8, < 3.0)
|
28
|
-
rexml (>= 3.2.5, < 4.0)
|
29
|
-
rubocop-ast (>= 1.28.0, < 2.0)
|
30
|
-
ruby-progressbar (~> 1.7)
|
31
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
32
|
-
rubocop-ast (1.28.0)
|
33
|
-
parser (>= 3.2.1.0)
|
34
|
-
ruby-progressbar (1.13.0)
|
35
|
-
simplecov (0.22.0)
|
36
|
-
docile (~> 1.1)
|
37
|
-
simplecov-html (~> 0.11)
|
38
|
-
simplecov_json_formatter (~> 0.1)
|
39
|
-
simplecov-html (0.12.3)
|
40
|
-
simplecov_json_formatter (0.1.4)
|
41
|
-
unicode-display_width (2.4.2)
|
42
|
-
|
43
|
-
PLATFORMS
|
44
|
-
x86_64-linux
|
45
|
-
|
46
|
-
DEPENDENCIES
|
47
|
-
microfsm!
|
48
|
-
minitest
|
49
|
-
observr
|
50
|
-
rake
|
51
|
-
ricecream
|
52
|
-
rubocop
|
53
|
-
simplecov
|
54
|
-
|
55
|
-
BUNDLED WITH
|
56
|
-
2.4.10
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2021-2023 Dittmar Krall (www.matiq.com)
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
data/microfsm.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
2
|
-
require "version"
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "microfsm"
|
6
|
-
s.version = MicroFSM::VERSION
|
7
|
-
s.summary = %(Minimal Finite State Machine.)
|
8
|
-
s.description = %{MicroFSM implements a minimal/simple Finite-State Machine (FSM). Transitions are triggered by events. Actions for a transition can be added as callbacks.}
|
9
|
-
s.authors = ["Dittmar Krall"]
|
10
|
-
s.email = "dittmar.krall@matiq.com"
|
11
|
-
s.homepage = "https://matiq.com"
|
12
|
-
s.license = "MIT"
|
13
|
-
s.platform = Gem::Platform::RUBY
|
14
|
-
|
15
|
-
s.metadata["source_code_uri"] = "https://github.com/matique/microfsm"
|
16
|
-
|
17
|
-
s.files = `git ls-files`.split("\n")
|
18
|
-
|
19
|
-
s.add_development_dependency "rake"
|
20
|
-
s.add_development_dependency "minitest"
|
21
|
-
end
|
data/test/callbacks_test.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
describe MicroFSM do
|
4
|
-
let(:fsm) {
|
5
|
-
MicroFSM.new(:pending)
|
6
|
-
.when(:confirm, pending: :confirmed) { @state = "Confirmed" }
|
7
|
-
.when(:reset, confirmed: :pending) { @state = "Pending" }
|
8
|
-
}
|
9
|
-
|
10
|
-
def test_executes_callbacks_during_transition
|
11
|
-
fsm.trigger(:confirm)
|
12
|
-
assert_equal "Confirmed", @state
|
13
|
-
|
14
|
-
fsm.trigger(:reset)
|
15
|
-
assert_equal "Pending", @state
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_two_callbacks_during_transition
|
19
|
-
fsm.when(:confirm, pending: :confirmed) { @state2 = "Confirmed2" }
|
20
|
-
|
21
|
-
fsm.trigger(:confirm)
|
22
|
-
assert_equal "Confirmed", @state
|
23
|
-
assert_equal "Confirmed2", @state2
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_passing_the_event_name_to_the_callbacks
|
27
|
-
event_name = nil
|
28
|
-
fsm.when(:confirm, pending: :confirmed) do |event|
|
29
|
-
event_name = event
|
30
|
-
end
|
31
|
-
|
32
|
-
fsm.trigger(:confirm)
|
33
|
-
assert_equal :confirm, event_name
|
34
|
-
end
|
35
|
-
end
|
data/test/introspection_test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
describe MicroFSM do
|
4
|
-
let(:fsm) {
|
5
|
-
MicroFSM.new(:pending)
|
6
|
-
.when(:confirm, pending: :confirmed)
|
7
|
-
.when(:ignore, pending: :ignored)
|
8
|
-
.when(:reset, confirmed: :pending, ignored: :pending)
|
9
|
-
}
|
10
|
-
|
11
|
-
def test_returns_an_array_with_the_defined_events
|
12
|
-
assert_equal %i[confirm ignore reset], fsm.events
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_list_the_available_events_for_the_current_state
|
16
|
-
assert_equal %i[confirm ignore], fsm.triggerable_events
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_returns_an_array_with_the_defined_states
|
20
|
-
assert_equal %i[confirmed ignored pending], fsm.states
|
21
|
-
end
|
22
|
-
end
|
data/test/microfsm_test.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
describe MicroFSM do
|
4
|
-
let(:fsm) {
|
5
|
-
MicroFSM.new(:pending)
|
6
|
-
.when(:confirm, pending: :confirmed)
|
7
|
-
.when(:ignore, pending: :ignored)
|
8
|
-
.when(:reset, confirmed: :pending, ignored: :pending)
|
9
|
-
}
|
10
|
-
|
11
|
-
def test_class
|
12
|
-
assert_kind_of MicroFSM, fsm
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_defines_initial_state
|
16
|
-
assert_equal :pending, fsm.state
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_changes_the_state
|
20
|
-
assert fsm.trigger?(:confirm)
|
21
|
-
assert fsm.trigger(:confirm)
|
22
|
-
assert_equal :confirmed, fsm.state
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_preserves_the_state_if_transition_is_not_possible
|
26
|
-
refute fsm.trigger?(:reset)
|
27
|
-
refute fsm.trigger(:reset)
|
28
|
-
assert_equal :pending, fsm.state
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_multiple_transitions
|
32
|
-
fsm.trigger(:confirm)
|
33
|
-
assert_equal :confirmed, fsm.state
|
34
|
-
|
35
|
-
fsm.trigger(:reset)
|
36
|
-
assert_equal :pending, fsm.state
|
37
|
-
|
38
|
-
fsm.trigger(:ignore)
|
39
|
-
assert_equal :ignored, fsm.state
|
40
|
-
|
41
|
-
fsm.trigger(:reset)
|
42
|
-
assert_equal :pending, fsm.state
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_raises_an_error_if_an_invalid_event_is_triggered
|
46
|
-
assert_raises(MicroFSM::InvalidEvent) do
|
47
|
-
fsm.trigger(:random_event)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_raises_error_if_trigger_from_incompatible_state
|
52
|
-
assert_raises(MicroFSM::InvalidState) do
|
53
|
-
fsm.trigger!(:reset)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_raises_an_error_if_a_transition_is_overwritten
|
58
|
-
fsm = MicroFSM.new(:init)
|
59
|
-
|
60
|
-
fsm.when(:trigger, init: :started)
|
61
|
-
assert_raises(MicroFSM::InvalidTransition) do
|
62
|
-
fsm.when(:trigger, init: :wrong)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_state_assign
|
67
|
-
new_state = :unknown
|
68
|
-
refute_equal new_state, fsm.state
|
69
|
-
fsm.state = new_state
|
70
|
-
assert_equal new_state, fsm.state
|
71
|
-
end
|
72
|
-
end
|