simplestate 2.0.8 → 2.0.9
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/CHANGE_NOTES.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/simplestate/state.rb +1 -1
- data/lib/simplestate/state_holder.rb +24 -24
- data/lib/simplestate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2eeced360d2d970ddc18e95401b388903ff8e0e2
|
|
4
|
+
data.tar.gz: 6cd6ed7bc7779a30dec624eac085fc5660f1b018
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f2e83e88fb1e693991ca0ed6d758503cf6c15509b771ea258f97ad0ab752b20f3833c0d78edc656bdf32aef4a2c6de4b847426cf32b4186c7da160aa48c6d4d8
|
|
7
|
+
data.tar.gz: 5b1aae54d1fa3518c9c2df59ba9f9e74a77203b0de5df2bfd82647ace956ec24269d7676b6c569340054d916c92e626e6a7d2b24b164455360b1d4409012a85d
|
data/CHANGE_NOTES.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
#### SimpleState version 2.1.0
|
|
2
|
+
Make stateholder#transition_to a private method. Should have done all along. This is not representative of an event but rather a handler of the internal process of changing states.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#### SimpleState version 2.0.8
|
|
6
|
+
Cleanup tests. Remove some cruft.
|
|
7
|
+
|
|
8
|
+
|
|
1
9
|
#### SimpleState version 2.0.7
|
|
2
10
|
Provide initial state in the call to StateHolder#start. The call signatures for StateHolder#initialize and #start remain supported. This may change with the next major version change. Note that the state history will no longer begin with :NullState.
|
|
3
11
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -72,7 +72,7 @@ Simplestate arose out of a desire for a very low ceremony mechanism to implement
|
|
|
72
72
|
|
|
73
73
|
The current version (2.0.0) is a rewrite of SimpleState. State logic is provided via instances of the appropriate subclasses of State. A state is referenced via a symbol created by symbolizing the state's name. A list of state instances available for transitions is maintained by the state holder in a hash keyed on the state symbols. This is an incomplete variant of the singleton pattern. It solved some issues I was having with the previous version of SimpleState, but please use some care. For example, there is no logic to actually prevent creation of more than one instance of a given State subclass. Doing this would likely create bugs that will eventually bite you. :-(
|
|
74
74
|
|
|
75
|
-
The StateHolder class provides the required functionality for a basic state machine: methods to set the initial state and to transition to a new state. To complement this a State class is provided to serve as ancestor to the states of the state holder. A State instance stores a reference to the state holder and a private __#transition\_to__ method which simply calls the state holder’s __#transition\_to__.
|
|
75
|
+
The StateHolder class provides the required functionality for a basic state machine: methods to set the initial state and to transition to a new state. To complement this a State class is provided to serve as ancestor to the states of the state holder. A State instance stores a reference to the state holder and a private __#transition\_to__ method which simply calls the state holder’s private __#transition\_to__. This calling of a private method of another object is usually to be avoided. Making state_holder#transition_to private is chosen here to allow indication that external users of the state machine should not use state_holder#transition_to. The state_holder and it's associated states are closely linked and share much knowledge about each other. They are "co-dependent" due to the choice of using SimpleDelegator. As such I believe it is acceptable for a state to call the private method in its corresponding state holder.
|
|
76
76
|
|
|
77
77
|
StateHolder and State are not expected to be used directly. Rather, they are intended to be the ancestors of the actual state holder and states. A state should provide only methods that are unique to it. Methods that are not specific to a state should be provided by the state holder. The public methods of a child state act as receivers of event messages via delegation from the state holder. Such events may cause effects that are managed by the current state and may also cause transition to a new state. State change logic is expected to be held within the current state. Two private methods, __#enter__ and __#exit__, *must* be provided by each state. These are called by the state holder __#transition_to__ method at the appropriate points in the state life cycle. Neither __#enter__ nor __#exit__ nor any other private method of a state are intended to be called by a user of the state holder. To avoid potentially stepping on the user's code __#enter__ and __#exit__ are called with __\_\_send\_\___.
|
|
78
78
|
|
data/lib/simplestate/state.rb
CHANGED
|
@@ -14,11 +14,6 @@ class StateHolder < SimpleDelegator
|
|
|
14
14
|
enter_new_state(init_state)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def transition_to(state)
|
|
18
|
-
leave_old_state
|
|
19
|
-
enter_new_state(state)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
17
|
# Convenience methods
|
|
23
18
|
def current_state
|
|
24
19
|
__getobj__
|
|
@@ -33,23 +28,28 @@ class StateHolder < SimpleDelegator
|
|
|
33
28
|
end
|
|
34
29
|
|
|
35
30
|
private
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
31
|
+
attr_reader :state_list, :state_history
|
|
32
|
+
def transition_to(state)
|
|
33
|
+
leave_old_state
|
|
34
|
+
enter_new_state(state)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def leave_old_state
|
|
38
|
+
current_state.__send__(:exit)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def enter_new_state(state)
|
|
42
|
+
self.current_state = state
|
|
43
|
+
state_history << current_state.symbol
|
|
44
|
+
current_state.__send__(:enter)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def current_state=(state)
|
|
48
|
+
state_obj = state_list[state]
|
|
49
|
+
__setobj__(state_obj)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def add_state(state_instance)
|
|
53
|
+
state_list.add state_instance
|
|
54
|
+
end
|
|
55
55
|
end
|
data/lib/simplestate/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simplestate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mitchell C Kuppinger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-09-
|
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|