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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58265afde90f565033e45fa0ccb67ec7b19f8278
4
- data.tar.gz: f5429f2ea2524d631611a9f822a4bbea12a0ec4b
3
+ metadata.gz: 2eeced360d2d970ddc18e95401b388903ff8e0e2
4
+ data.tar.gz: 6cd6ed7bc7779a30dec624eac085fc5660f1b018
5
5
  SHA512:
6
- metadata.gz: 6e3b31aa17b7759176c30e1721bba7c7608fb588fe4f6a42d6ad4c60599fc635ed19ad3e1c56f6787eeffe3e1730278431dc8da986aaffde23c82945a7d04d74
7
- data.tar.gz: 16d1d0504139ec6aaf6c094f2459d762077e2e1a2b2f17400e38dd187032e2061a411dfcb00067f197ad33727830be5e1bbe63ea4c68b25ebf6c729502e74ceb
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simplestate (2.0.7)
4
+ simplestate (2.0.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
 
@@ -16,7 +16,7 @@ class State
16
16
 
17
17
  private
18
18
  def transition_to(state)
19
- holder.transition_to(state)
19
+ holder.__send__ :transition_to, state
20
20
  end
21
21
 
22
22
  def enter
@@ -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
- attr_reader :state_list, :state_history
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
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
@@ -1,3 +1,3 @@
1
1
  module Simplestate
2
- VERSION = "2.0.8"
2
+ VERSION = "2.0.9"
3
3
  end
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.8
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-15 00:00:00.000000000 Z
11
+ date: 2016-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler