simply_fsm 0.2.1 → 0.2.3
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/.gitignore +3 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +5 -1
- data/Rakefile +7 -0
- data/lib/simply_fsm/version.rb +1 -1
- data/lib/simply_fsm.rb +47 -24
- data/simply_fsm.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ae5d7b10e3ba09f4838625a6de8dd2314b68246628efed8d950fe087f34f1d7
|
|
4
|
+
data.tar.gz: cb2f1af32ed62f1032e902391543e6347d0c367eabbe1795e0caf067099baece
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7f8e0821322ec9e24b9eb5626d59c30e8fa5863d174c53c1d77d041351a635f0a690a111057c3bbd8d58e2aa8418384996314fb39e1f43db3c31c825f229045b
|
|
7
|
+
data.tar.gz: f7fc248239ca69a84f54ac8a94e25e6bcfc7986e37c40c4bd2dbc5936d4e2a4168be5afbef66351c94f7aabc07debc27ab78ff8133426a6d140082a19f2f2138
|
data/.gitignore
CHANGED
data/.yardopts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--no-private
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
- None right now
|
|
4
4
|
|
|
5
|
+
## [0.2.3] - 2022-04-09
|
|
6
|
+
|
|
7
|
+
- Add `rake yard` to generate local documentation
|
|
8
|
+
- Clean up API documentation
|
|
9
|
+
- Privatise some internal methods
|
|
10
|
+
|
|
11
|
+
## [0.2.2] - 2022-03-08
|
|
12
|
+
|
|
13
|
+
- Call `fail` lambda without wrapping it in a lambda
|
|
14
|
+
|
|
5
15
|
## [0.2.1] - 2022-03-05
|
|
6
16
|
|
|
7
17
|
- Fixed bug where named fail handlers were not called properly for multi-transition events.
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
simply_fsm (0.2.
|
|
4
|
+
simply_fsm (0.2.3)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -46,6 +46,9 @@ GEM
|
|
|
46
46
|
ruby-progressbar (1.11.0)
|
|
47
47
|
stringio (3.0.1)
|
|
48
48
|
unicode-display_width (2.1.0)
|
|
49
|
+
webrick (1.7.0)
|
|
50
|
+
yard (0.9.27)
|
|
51
|
+
webrick (~> 1.7.0)
|
|
49
52
|
|
|
50
53
|
PLATFORMS
|
|
51
54
|
ruby
|
|
@@ -56,6 +59,7 @@ DEPENDENCIES
|
|
|
56
59
|
rspec (~> 3.0)
|
|
57
60
|
rubocop (~> 1.21)
|
|
58
61
|
simply_fsm!
|
|
62
|
+
yard
|
|
59
63
|
|
|
60
64
|
BUNDLED WITH
|
|
61
65
|
2.1.4
|
data/Rakefile
CHANGED
|
@@ -17,6 +17,13 @@ Rake::RDocTask.new do |rdoc|
|
|
|
17
17
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
require "yard"
|
|
21
|
+
|
|
22
|
+
YARD::Rake::YardocTask.new do |t|
|
|
23
|
+
t.files = ["lib/**/*.rb"]
|
|
24
|
+
t.stats_options = ["--list-undoc"]
|
|
25
|
+
end
|
|
26
|
+
|
|
20
27
|
RuboCop::RakeTask.new
|
|
21
28
|
|
|
22
29
|
task default: %i[spec rubocop]
|
data/lib/simply_fsm/version.rb
CHANGED
data/lib/simply_fsm.rb
CHANGED
|
@@ -2,31 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
require "simply_fsm/version"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Include *SimplyFSM* in a class to be able to defined state machines.
|
|
7
|
+
#
|
|
7
8
|
module SimplyFSM
|
|
9
|
+
#
|
|
10
|
+
# Provides a +state_machine+ for the including class.
|
|
8
11
|
def self.included(base)
|
|
9
12
|
base.extend(ClassMethods)
|
|
10
13
|
end
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
return true if from == :any
|
|
14
|
-
return from.include?(current) if from.is_a?(Array)
|
|
15
|
-
|
|
16
|
-
from == current
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def cannot_transition?(from, cond, current)
|
|
20
|
-
(from && !state_match?(from, current)) || (cond && !instance_exec(&cond))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
##
|
|
15
|
+
#
|
|
24
16
|
# Defines the constructor for defining a state machine
|
|
25
17
|
module ClassMethods
|
|
26
|
-
|
|
18
|
+
#
|
|
27
19
|
# Declare a state machine called +name+ which can then be defined
|
|
28
|
-
# by a DSL defined by the methods of
|
|
29
|
-
#
|
|
20
|
+
# by a DSL defined by the methods of *StateMachine*.
|
|
21
|
+
#
|
|
22
|
+
# @param [String] name of the state machine.
|
|
23
|
+
# @param [Hash] opts to specify options such as:
|
|
24
|
+
# - +fail+ lambda that is called with the event name when any event fails to transition
|
|
25
|
+
#
|
|
30
26
|
def state_machine(name, opts = {}, &block)
|
|
31
27
|
fsm = StateMachine.new(name, self, fail: opts[:fail])
|
|
32
28
|
fsm.instance_eval(&block)
|
|
@@ -34,10 +30,19 @@ module SimplyFSM
|
|
|
34
30
|
end
|
|
35
31
|
|
|
36
32
|
##
|
|
37
|
-
# The DSL for defining a state machine
|
|
33
|
+
# The DSL for defining a state machine. These methods are used within the declaration of a +state_machine+.
|
|
34
|
+
#
|
|
35
|
+
# @attr_reader [String] initial_state The initial state of the state machine
|
|
36
|
+
# @attr_reader [Array] states All the states of the state machine
|
|
37
|
+
# @attr_reader [Array] events All the events of the state machine
|
|
38
|
+
# @attr_reader [String] name
|
|
39
|
+
# @attr_reader [String] full_name The name of the owning class combined with the state machine's name
|
|
40
|
+
#
|
|
38
41
|
class StateMachine
|
|
39
42
|
attr_reader :initial_state, :states, :events, :name, :full_name
|
|
40
43
|
|
|
44
|
+
#
|
|
45
|
+
# @!visibility private
|
|
41
46
|
def initialize(name, owner_class, fail: nil)
|
|
42
47
|
@owner_class = owner_class
|
|
43
48
|
@name = name.to_sym
|
|
@@ -50,8 +55,12 @@ module SimplyFSM
|
|
|
50
55
|
setup_base_methods
|
|
51
56
|
end
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
#
|
|
54
59
|
# Declare a supported +state_name+, and optionally specify one as the +initial+ state.
|
|
60
|
+
#
|
|
61
|
+
# @param [String] state_name
|
|
62
|
+
# @param [Boolean] initial to indicate if this is the initial state of the state machine
|
|
63
|
+
#
|
|
55
64
|
def state(state_name, initial: false)
|
|
56
65
|
return if state_name.nil? || @states.include?(state_name)
|
|
57
66
|
|
|
@@ -68,10 +77,11 @@ module SimplyFSM
|
|
|
68
77
|
##
|
|
69
78
|
# Define an event by +event_name+
|
|
70
79
|
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
#
|
|
80
|
+
# @param [String] event_name
|
|
81
|
+
# @param [Hash,Array] transitions either one (Hash) or many (Array of Hashes) transitions +from+ one state +to+ another state.
|
|
82
|
+
# @param [Lambda] guard if specified must return +true+ before any transitions are attempted
|
|
83
|
+
# @param [Lambda] fail called with event name if specified when all the attempted transitions fail
|
|
84
|
+
# @yield when the transition attempt succeeds.
|
|
75
85
|
def event(event_name, transitions:, guard: nil, fail: nil, &after)
|
|
76
86
|
return unless event_exists?(event_name) && transitions
|
|
77
87
|
|
|
@@ -119,7 +129,7 @@ module SimplyFSM
|
|
|
119
129
|
if fail.is_a?(String) || fail.is_a?(Symbol)
|
|
120
130
|
->(event_name) { send(fail, event_name) }
|
|
121
131
|
else
|
|
122
|
-
|
|
132
|
+
fail
|
|
123
133
|
end
|
|
124
134
|
end
|
|
125
135
|
|
|
@@ -254,4 +264,17 @@ module SimplyFSM
|
|
|
254
264
|
@owner_class.define_method(method_name, method_definition)
|
|
255
265
|
end
|
|
256
266
|
end
|
|
267
|
+
|
|
268
|
+
private
|
|
269
|
+
|
|
270
|
+
def state_match?(from, current)
|
|
271
|
+
return true if from == :any
|
|
272
|
+
return from.include?(current) if from.is_a?(Array)
|
|
273
|
+
|
|
274
|
+
from == current
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def cannot_transition?(from, cond, current)
|
|
278
|
+
(from && !state_match?(from, current)) || (cond && !instance_exec(&cond))
|
|
279
|
+
end
|
|
257
280
|
end
|
data/simply_fsm.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simply_fsm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- nogginly
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-04-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rdoc
|
|
@@ -24,6 +24,20 @@ dependencies:
|
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: yard
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: rspec
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -49,6 +63,7 @@ files:
|
|
|
49
63
|
- ".rspec"
|
|
50
64
|
- ".rubocop.yml"
|
|
51
65
|
- ".ruby-version"
|
|
66
|
+
- ".yardopts"
|
|
52
67
|
- CHANGELOG.md
|
|
53
68
|
- CODE_OF_CONDUCT.md
|
|
54
69
|
- Gemfile
|