simplestate 1.0.4 → 1.0.5

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -4
  3. data/lib/simplestate/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcc388adfc88a6cd589baa29286bc560d25ccd62
4
- data.tar.gz: f86c3672aacec20a2634602d52eccd699b72a124
3
+ metadata.gz: 2e1f8cc60b7d971102eb515eee2ad348019ee584
4
+ data.tar.gz: 7fa1b45429847b3bde13bedc3f54d61a807c8666
5
5
  SHA512:
6
- metadata.gz: 7d5546df5a9f232656fdc47950ebd0d120993e43966c5145f4e0130308fce0d4b3fb2e0a066e3588844e02c781de9739df5a27d57730106b5a9702ac601d0183
7
- data.tar.gz: b0624f028f997363913ebc04b2ee4c88135e8707ea61bf4b1730f55dc9adddf343396e0aa0952de97cf8178c71239307ad0b644ef77be3d195ef53c4e8161d66
6
+ metadata.gz: 18351282659d21e6279bd8901241de36b067616d4e5684af05babf72b9e6d48a4ed22ea81957cfedff6435dda577864f794a1fbf5c788d5e367babd262384e90
7
+ data.tar.gz: 18915fdb2f13b90e816f61c80162d84b1804434b56dda0b2cddb8c1a9040bce8f8c04fa11e0d8e203d0c47d3ef663b307a4c60ab5618b8962bd5a84ceaf8222f
data/README.md CHANGED
@@ -11,10 +11,16 @@ end
11
11
 
12
12
  class Off < State
13
13
  def press; transition_to(On); end
14
+ private
15
+ def enter; end
16
+ def exit; end
14
17
  end
15
18
 
16
19
  class On < State
17
20
  def press; transition_to(Off); end
21
+ private
22
+ def enter; end
23
+ def exit; end
18
24
  end
19
25
 
20
26
  button = Button.new(start_in: Off)
@@ -22,17 +28,17 @@ button.press # current_state: On
22
28
  button.press # current_state: Off
23
29
  ````
24
30
  # Description
25
- Simplestate arose out of a desire for a very low ceremony mechanism to implement a state machine. I have used SimpleDelegator (delegate.rb) to implement this. Because SimpleDelegator supports dynamically swapping the object to which methods are delegated, it provides a good base for Simplestate.
31
+ Simplestate arose out of a desire for a very low ceremony mechanism to implement a state machine. SimpleDelegator (delegate.rb) is used to implement this. Because SimpleDelegator supports dynamically swapping the object to which methods are delegated, it provides a good base for Simplestate.
26
32
 
27
33
  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 machine. A State instance stores a reference to the state holder and a __#transition_to__ method which simply calls the state holder's __#transition_to__.
28
34
 
29
35
  StateHolder and State are not expected to be used directly. Rather, they are intended to be inherited from. The child state holder should provide methods not specific to its current state. A child state should provide methods specific to that state. 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.
30
36
 
31
- For convenience StateHolder provides instance methods, __#current_state__ and __#set_new_state__, to provide easy access to the underlying methods, __\_\_getobj\_\___ and __\_\_setobj\_\___, of SimpleDelegator. A method to retrieve the history of state transitions from the state holder, __#state_history__, is also provided. Since the transition history could grow quite large that history is limited to the last 5 transitions by default. The history size limit may be changed via __#hx_size_limit__. That limit may be changed at any time. Changes to the limit will take effect an the next state transition.
37
+ For convenience StateHolder provides instance methods, __#current_state__ and __#set_new_state__, to provide easy access to the underlying methods, __\_\_getobj\_\___ and __\_\_setobj\_\___, of SimpleDelegator. A method to retrieve the history of state transitions from the state holder, __#state_history__, is also provided. Since the transition history could grow quite large that history is limited to the last 5 transitions by default. The history size limit may be changed via __#hx_size_limit__. That limit may be changed at any time. Changes to the limit will take effect at the next state transition.
32
38
 
33
39
  Simplestate does not provide a DSL for specifying the events, states and allowed state transitions. That logic must be specified within each state. Neither does Simplestate provide any mechanism for serialization. There is no "magic" here. It is just a couple of PORO's. As such, it is very easy to see and to reason about what is happening within Simplestate. It should not be too difficult to add serialization support to Simplestate.
34
40
 
35
- As an aside, I have looked into providing the Simplestate functionality via a module. However, I found that the SimpleDelegator class provides delegation via a mechanism that makes a module based Simplestate implementation very difficult to achieve. The complexity of that implementation seemed to be not worth the effort. I think the StatePattern gem by [Daniel Cadenas](https://github.com/dcadenas/state_pattern), the inspiration for Simplestate, ran into just this problem. I chose to avoid that issue by relying solely on inheritance.
41
+ As an aside, I have looked into providing the Simplestate functionality via a module. However, I found that the SimpleDelegator class provides delegation via a mechanism that makes a module based Simplestate implementation very difficult to achieve. The complexity of that implementation seemed to be not worth the effort. I think the [StatePattern](https://github.com/dcadenas/state_pattern) gem by Daniel Cadenas, the inspiration for Simplestate, ran into just this problem. I chose to avoid that issue by relying solely on inheritance.
36
42
 
37
43
 
38
44
  ## Installation
@@ -139,7 +145,7 @@ end
139
145
 
140
146
  Please note that the State instance method, __#previous_state_class__, has been removed in this release.
141
147
 
142
- #### version 0.3.0 addition
148
+ #### version 0.3.0
143
149
  The 0.3.0 version contained a serious code smell: A state was expected to know about the history of state transitions. However, a state should know only the states to which it may transition and it's holder to support triggering those transitions. Knowlege of the transition history belongs with the state holder, if it is tracked at all.
144
150
 
145
151
  #### usage example
@@ -153,6 +159,8 @@ If a DSL is desired, complex state functionality is required, events may arrive
153
159
 
154
160
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
155
161
 
162
+ StateHolderInterfaceTest and StateInterfaceTest are provided to verify that your state holder and state instances respond to the minimum required method calls for each. Simply include these in the tests of your decendents of StateHolder and State and in any dummies of these classes you may use in your tests.
163
+
156
164
  To install this gem onto your local machine, run `bundle exec rake install`.
157
165
 
158
166
  ## Contributing
@@ -1,3 +1,3 @@
1
1
  module Simplestate
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplestate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell C Kuppinger