simplestate 2.0.6 → 2.0.7
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 +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +22 -6
- data/lib/simplestate/null_state.rb +2 -5
- data/lib/simplestate/state_holder.rb +10 -10
- 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: db5428361e6e4a05f7b412039b9d2d4573d0347a
|
|
4
|
+
data.tar.gz: 32e57aa972d3dc98978d67091a60be22094151a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1d76b961961d90952e91af330cd86581a9f2c8168296cbd0e329c6dfd98fdf7de09c9144c0f5c38e17b18a029dbaaa0b93b9ea7684ad31e25f1d93b445297520
|
|
7
|
+
data.tar.gz: 023400cb7e1f81178ba104d29d2517ad2aaead23c443f75f97bcc26a0ffc071466190a675080296fe550497fb8885e45eb77b1179591e727df2faed2228d3b4f
|
data/CHANGE_NOTES.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
#### SimpleState version 2.0.7
|
|
2
|
+
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
|
+
|
|
4
|
+
|
|
1
5
|
#### SimpleState version 2.0.6
|
|
2
6
|
Remove some cruft from testing setup.
|
|
3
7
|
Code grooming.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
```ruby
|
|
8
8
|
class Button < StateHolder
|
|
9
9
|
attr_reader :name
|
|
10
|
-
def initialize(
|
|
10
|
+
def initialize(opts: {})
|
|
11
11
|
@name = opts.fetch :name
|
|
12
12
|
super
|
|
13
13
|
end
|
|
@@ -107,7 +107,7 @@ Inherit from StateHolder to create the class of the object that will hold states
|
|
|
107
107
|
```ruby
|
|
108
108
|
class Button < StateHolder
|
|
109
109
|
attr_reader :color
|
|
110
|
-
def initialize(
|
|
110
|
+
def initialize(opts: {})
|
|
111
111
|
@color = opts.fetch :color
|
|
112
112
|
super
|
|
113
113
|
end
|
|
@@ -116,17 +116,33 @@ class Button < StateHolder
|
|
|
116
116
|
end
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
Creation of a StateHolder instance
|
|
119
|
+
Creation of a StateHolder instance may specify the initial state. StateHolder expects to receive the initial state as a symbol based on the state name. The name case is preserved in creating the symbol.:
|
|
120
120
|
|
|
121
121
|
```ruby
|
|
122
122
|
button = Button.new( initial_state: :Off )
|
|
123
123
|
```
|
|
124
|
+
or
|
|
125
|
+
```ruby
|
|
126
|
+
button = Button.new()
|
|
127
|
+
```
|
|
124
128
|
If you want to set additional attributes at creation of a new button, do so within the opts hash when new is called. Set the attribute from the opts hash in initialize.
|
|
125
129
|
|
|
126
130
|
```ruby
|
|
127
|
-
button = Button.new(
|
|
128
|
-
|
|
131
|
+
button = Button.new( opts: {color: 'Red'} )
|
|
132
|
+
```
|
|
133
|
+
After creation of a state holder it must be started:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
button = Button.new
|
|
137
|
+
button.start(:Off)
|
|
129
138
|
```
|
|
139
|
+
If the initial state is not directly supplied to the start method, then it must have been supplied at state holder creation:
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
button = Button.new( initial_state: :Off )
|
|
143
|
+
button.start
|
|
144
|
+
```
|
|
145
|
+
|
|
130
146
|
|
|
131
147
|
#### States
|
|
132
148
|
|
|
@@ -159,7 +175,7 @@ holder.specialmethod
|
|
|
159
175
|
```
|
|
160
176
|
|
|
161
177
|
#### Usage Example
|
|
162
|
-
The button module (test/
|
|
178
|
+
The button module (test/dummy/button.rb) provides an example of the usage of Simplestate. Tests of this are provided in button\_test.rb.
|
|
163
179
|
|
|
164
180
|
A working minimal example app is provided at ```https://github.com/dpneumo/simplestate-demo```
|
|
165
181
|
|
|
@@ -3,12 +3,9 @@ class NullState
|
|
|
3
3
|
# Avoid chicken and egg problem by mimicing rather than inheriting from State
|
|
4
4
|
|
|
5
5
|
attr_reader :holder
|
|
6
|
-
def initialize(holder
|
|
6
|
+
def initialize(holder:, opts: {})
|
|
7
7
|
@holder = holder
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def self.list
|
|
11
|
-
{}
|
|
8
|
+
@holder.__send__(:add_state, self)
|
|
12
9
|
end
|
|
13
10
|
|
|
14
11
|
def name
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
class StateHolder < SimpleDelegator
|
|
2
|
-
attr_reader :initial_state
|
|
2
|
+
attr_reader :initial_state
|
|
3
3
|
|
|
4
|
-
def initialize(initial_state
|
|
5
|
-
|
|
4
|
+
def initialize( initial_state: nil,
|
|
5
|
+
state_history: StateHistory.new,
|
|
6
|
+
state_list: StateList.new,
|
|
7
|
+
opts: {})
|
|
6
8
|
@state_history = state_history
|
|
7
|
-
@state_list
|
|
8
|
-
|
|
9
|
-
super(NullState.new)
|
|
9
|
+
@state_list = state_list
|
|
10
|
+
super
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
def start
|
|
13
|
-
|
|
14
|
-
transition_to(initial_state)
|
|
13
|
+
def start(init_state=initial_state)
|
|
14
|
+
enter_new_state(init_state)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def transition_to(state)
|
|
@@ -33,7 +33,7 @@ class StateHolder < SimpleDelegator
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
private
|
|
36
|
-
attr_reader :state_list
|
|
36
|
+
attr_reader :state_list, :state_history
|
|
37
37
|
def leave_old_state
|
|
38
38
|
current_state.__send__(:exit)
|
|
39
39
|
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.7
|
|
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-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|