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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -9
  3. data/lib/simplestate/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e1f8cc60b7d971102eb515eee2ad348019ee584
4
- data.tar.gz: 7fa1b45429847b3bde13bedc3f54d61a807c8666
3
+ metadata.gz: 98120d72e903183f217fc3f3b3ab4e4ef41f3aa8
4
+ data.tar.gz: 1c02dc9ec7c5830b9701a86e23593aa9fd1810df
5
5
  SHA512:
6
- metadata.gz: 18351282659d21e6279bd8901241de36b067616d4e5684af05babf72b9e6d48a4ed22ea81957cfedff6435dda577864f794a1fbf5c788d5e367babd262384e90
7
- data.tar.gz: 18915fdb2f13b90e816f61c80162d84b1804434b56dda0b2cddb8c1a9040bce8f8c04fa11e0d8e203d0c47d3ef663b307a4c60ab5618b8962bd5a84ceaf8222f
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; end
16
- def exit; end
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; end
23
- def exit; end
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 # current_state: On
28
- button.press # current_state: Off
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
- Inherit from StateHolder to create the class of the object that will hold states:
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. Creation of a holder instance *must* specify the initial state class:
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. You *must* call super if you provide an initialize method in your holder class.
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
 
@@ -1,3 +1,3 @@
1
1
  module Simplestate
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
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: 1.0.5
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-08 00:00:00.000000000 Z
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler