microfsm 0.1.7 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +5 -2
- data/lib/microfsm/version.rb +13 -0
- data/lib/{version.rb → microfsm/version.rb.bak} +2 -1
- metadata +14 -23
- data/.github/workflows/rake.yml +0 -22
- data/.gitignore +0 -11
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -60
- data/LICENSE +0 -21
- data/Rakefile +0 -10
- data/microfsm.gemspec +0 -19
- 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: a01daa1886bcb3bd776f670e34fb6dae95a817707e6061bddbded1cec021661b
|
4
|
+
data.tar.gz: 28775fed9e92be9913912508ec3ca66c27e70d361d7bbe17c08bd84ce6170d25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9734e1f849e44ccae2a55e1f2f48487980a0965ad25464b1b3a65f07e31cc27a23be56ede14ea8a28db569637f3be4e7830e32bfe59cf5106c8dd9d97791c357
|
7
|
+
data.tar.gz: cf2b4b5d2be2e14b8711922c6bd3143134f807fcdf78490c7c6b1ab622894fb54aad7552324a7d0bf2f8eb079d39093f4c82fbfd4ca3bd3378a37ac8b54b2e73
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2021-2024 Dittmar Krall (www.matiq.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/microfsm.svg)](https://badge.fury.io/rb/microfsm)
|
4
4
|
[![GEM Downloads](https://img.shields.io/gem/dt/microfsm?color=168AFE&logo=ruby&logoColor=FE1616)](https://rubygems.org/gems/microfsm)
|
5
|
+
[![rake](https://github.com/matique/microfsm/actions/workflows/rake.yml/badge.svg)](https://github.com/matique/microfsm/actions/workflows/rake.yml)
|
6
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard)
|
7
|
+
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://choosealicense.com/licenses/mit/)
|
5
8
|
|
6
9
|
MicroFSM implements a minimal/simple Finite-State Machine (FSM).
|
7
10
|
Transitions are triggered by events.
|
@@ -97,7 +100,7 @@ fsm.state = :new
|
|
97
100
|
fsm.state #=> :new
|
98
101
|
```
|
99
102
|
|
100
|
-
Check the
|
103
|
+
Check the _examples_ directory for more information.
|
101
104
|
|
102
105
|
## Links
|
103
106
|
|
@@ -106,5 +109,5 @@ Check the examples directory for more information.
|
|
106
109
|
|
107
110
|
## Miscellaneous
|
108
111
|
|
109
|
-
Copyright (c) 2021-
|
112
|
+
Copyright (c) 2021-2024 Dittmar Krall (www.matiq.com),
|
110
113
|
released under the [MIT license](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class MicroFSM
|
4
|
+
VERSION = "0.1.10" # 2024-10-20
|
5
|
+
# VERSION = "0.1.9" # 2024-05-22
|
6
|
+
# VERSION = "0.1.7" # 2023-12-12
|
7
|
+
# VERSION = "0.1.6" # 2023-04-25
|
8
|
+
# VERSION = "0.1.5" # 2022-12-22
|
9
|
+
# VERSION = "0.1.3" # 2021-06-22
|
10
|
+
# VERSION = "0.1.2" # 2021-02-10
|
11
|
+
# VERSION = "0.1.1" # 2021-02-08
|
12
|
+
# VERSION = "0.0.1" # 2021-01-24
|
13
|
+
end
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-20 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,23 @@ 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
|
-
- microfsm.
|
63
|
-
- test/callbacks_test.rb
|
64
|
-
- test/introspection_test.rb
|
65
|
-
- test/microfsm_test.rb
|
66
|
-
- test/test_helper.rb
|
56
|
+
- lib/microfsm/version.rb
|
57
|
+
- lib/microfsm/version.rb.bak
|
67
58
|
homepage: https://github.com/matique/microfsm
|
68
59
|
licenses:
|
69
60
|
- MIT
|
70
61
|
metadata: {}
|
71
|
-
post_install_message:
|
62
|
+
post_install_message:
|
72
63
|
rdoc_options: []
|
73
64
|
require_paths:
|
74
65
|
- lib
|
@@ -83,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
74
|
- !ruby/object:Gem::Version
|
84
75
|
version: '0'
|
85
76
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
77
|
+
rubygems_version: 3.5.20
|
78
|
+
signing_key:
|
88
79
|
specification_version: 4
|
89
80
|
summary: Minimal Finite State Machine.
|
90
81
|
test_files: []
|
data/.github/workflows/rake.yml
DELETED
@@ -1,22 +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
|
-
ruby_version: ["3.0", 3.2]
|
12
|
-
runs-on: ubuntu-latest
|
13
|
-
|
14
|
-
steps:
|
15
|
-
- uses: actions/checkout@v3
|
16
|
-
- name: Set up Ruby
|
17
|
-
uses: ruby/setup-ruby@v1
|
18
|
-
with:
|
19
|
-
ruby-version: ${{ matrix.ruby_version }}
|
20
|
-
bundler-cache: true
|
21
|
-
- name: Build and test with Rake
|
22
|
-
run: bundle exec rake
|
data/.gitignore
DELETED
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rails-7.1
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-3.2.2
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
microfsm (0.1.7)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.2)
|
10
|
-
docile (1.4.0)
|
11
|
-
json (2.7.1)
|
12
|
-
language_server-protocol (3.17.0.3)
|
13
|
-
minitest (5.20.0)
|
14
|
-
observr (1.0.5)
|
15
|
-
parallel (1.23.0)
|
16
|
-
parser (3.2.2.4)
|
17
|
-
ast (~> 2.4.1)
|
18
|
-
racc
|
19
|
-
racc (1.7.3)
|
20
|
-
rainbow (3.1.1)
|
21
|
-
rake (13.1.0)
|
22
|
-
regexp_parser (2.8.3)
|
23
|
-
rexml (3.2.6)
|
24
|
-
ricecream (0.2.1)
|
25
|
-
rubocop (1.59.0)
|
26
|
-
json (~> 2.3)
|
27
|
-
language_server-protocol (>= 3.17.0)
|
28
|
-
parallel (~> 1.10)
|
29
|
-
parser (>= 3.2.2.4)
|
30
|
-
rainbow (>= 2.2.2, < 4.0)
|
31
|
-
regexp_parser (>= 1.8, < 3.0)
|
32
|
-
rexml (>= 3.2.5, < 4.0)
|
33
|
-
rubocop-ast (>= 1.30.0, < 2.0)
|
34
|
-
ruby-progressbar (~> 1.7)
|
35
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
36
|
-
rubocop-ast (1.30.0)
|
37
|
-
parser (>= 3.2.1.0)
|
38
|
-
ruby-progressbar (1.13.0)
|
39
|
-
simplecov (0.22.0)
|
40
|
-
docile (~> 1.1)
|
41
|
-
simplecov-html (~> 0.11)
|
42
|
-
simplecov_json_formatter (~> 0.1)
|
43
|
-
simplecov-html (0.12.3)
|
44
|
-
simplecov_json_formatter (0.1.4)
|
45
|
-
unicode-display_width (2.5.0)
|
46
|
-
|
47
|
-
PLATFORMS
|
48
|
-
x86_64-linux
|
49
|
-
|
50
|
-
DEPENDENCIES
|
51
|
-
microfsm!
|
52
|
-
minitest
|
53
|
-
observr
|
54
|
-
rake
|
55
|
-
ricecream
|
56
|
-
rubocop
|
57
|
-
simplecov
|
58
|
-
|
59
|
-
BUNDLED WITH
|
60
|
-
2.4.22
|
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,19 +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://github.com/matique/microfsm"
|
12
|
-
s.license = "MIT"
|
13
|
-
s.platform = Gem::Platform::RUBY
|
14
|
-
|
15
|
-
s.files = `git ls-files`.split("\n")
|
16
|
-
|
17
|
-
s.add_development_dependency "rake"
|
18
|
-
s.add_development_dependency "minitest"
|
19
|
-
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
|