simplestate 1.0.5 → 1.0.6
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/README.md +24 -9
- 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: 98120d72e903183f217fc3f3b3ab4e4ef41f3aa8
|
|
4
|
+
data.tar.gz: 1c02dc9ec7c5830b9701a86e23593aa9fd1810df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9348c67eb908105f981aea17d1998d6ed535e5bb613b790e6558169481615610a3ac71b0c648f0db8f842f7549aed870208d6056edb4f21ec65f23308f4e649e
|
|
7
|
+
data.tar.gz: ccee6da7323d35f86f36c55a6d905866ebe544f574ad3d981e2fa3637c6d20d7b403b352527334363e2611868fb573de7760d59a9c16c5d205c3482fa0a7a441
|
data/README.md
CHANGED
|
@@ -12,20 +12,32 @@ end
|
|
|
12
12
|
class Off < State
|
|
13
13
|
def press; transition_to(On); end
|
|
14
14
|
private
|
|
15
|
-
def enter
|
|
16
|
-
|
|
15
|
+
def enter
|
|
16
|
+
# send_message_to_log("entering off state")
|
|
17
|
+
# turn_light_off
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def exit
|
|
21
|
+
# send_message_to_log("leaving off state")
|
|
22
|
+
end
|
|
17
23
|
end
|
|
18
24
|
|
|
19
25
|
class On < State
|
|
20
26
|
def press; transition_to(Off); end
|
|
21
27
|
private
|
|
22
|
-
def enter
|
|
23
|
-
|
|
28
|
+
def enter
|
|
29
|
+
# send_message_to_log("entering on state")
|
|
30
|
+
# turn_light_on
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def exit
|
|
34
|
+
# send_message_to_log("leaving on state")
|
|
35
|
+
end
|
|
24
36
|
end
|
|
25
37
|
|
|
26
38
|
button = Button.new(start_in: Off)
|
|
27
|
-
button.press
|
|
28
|
-
button.press
|
|
39
|
+
button.press #=> current_state: On
|
|
40
|
+
button.press #=> current_state: Off
|
|
29
41
|
````
|
|
30
42
|
# Description
|
|
31
43
|
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.
|
|
@@ -58,7 +70,9 @@ Or install it yourself as:
|
|
|
58
70
|
$ gem install simplestate
|
|
59
71
|
|
|
60
72
|
## Usage
|
|
61
|
-
|
|
73
|
+
|
|
74
|
+
#### State Holder
|
|
75
|
+
Inherit from StateHolder to create the class of the object that will hold states. You *must* call super if you provide an initialize method in your holder class:
|
|
62
76
|
|
|
63
77
|
```ruby
|
|
64
78
|
class Button < StateHolder
|
|
@@ -72,7 +86,7 @@ class Button < StateHolder
|
|
|
72
86
|
end
|
|
73
87
|
```
|
|
74
88
|
|
|
75
|
-
StateHolder expects to receive the initial state class in an opts hash at creation
|
|
89
|
+
Creation of a StateHolder instance *must* specify the initial state class. StateHolder expects to receive the initial state class in an opts hash at creation:
|
|
76
90
|
|
|
77
91
|
```ruby
|
|
78
92
|
button = Button.new(initial_state_class: Off)
|
|
@@ -82,12 +96,13 @@ or use this alternate syntax:
|
|
|
82
96
|
```ruby
|
|
83
97
|
button = Button.new(start_in: Off)
|
|
84
98
|
```
|
|
85
|
-
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.
|
|
99
|
+
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.
|
|
86
100
|
|
|
87
101
|
```ruby
|
|
88
102
|
button = Button.new(start_in: Off, color: 'Red')
|
|
89
103
|
```
|
|
90
104
|
|
|
105
|
+
#### States
|
|
91
106
|
|
|
92
107
|
Inherit from State to create a class to provide specific state behaviors:
|
|
93
108
|
|
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: 1.0.
|
|
4
|
+
version: 1.0.6
|
|
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-02-
|
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|