simplestate 0.1.6 → 0.2.0

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: 1c017617be36d0cbfb928ecdfa4cc18257a2962d
4
- data.tar.gz: 53e41c6cc17d58b45e37e2ea988e651b7bcdee6a
3
+ metadata.gz: 450c34a364264d7b24164fde023f5bcec59b9a08
4
+ data.tar.gz: cade1b14539a4590e7bcd4a36444209cabdf9d22
5
5
  SHA512:
6
- metadata.gz: e8bdfbcd3eb58fe841ea42f674abadd76f61d7ec0fcf79f0600ac93980228e5977676016a9dfa4e0d251fc0174ec36455975666e9435551cdd0949cac9b6cd5a
7
- data.tar.gz: 8781ea5e2562ca7022f83b3cefd1e8e935e1f71730fe7d372645186a276f6c8ab10364a797ea2da037fa065344064cda03b55d258d75a577d9a16e3b35e710e9
6
+ metadata.gz: eceab10c44577b6674d3307bbab54cc26d562c06cd27032937133d29ea056df1def64dd1b656a8d546027091e77e2f625936f9b4b396db33d94a745207660017
7
+ data.tar.gz: c55a2fdb9a61a24471905e4605a32b9590ef0842ec312056f9105abd0c761c769a628dae4148f1021fedc4725145f09d2d5041033826d3c794628951ead2bf99
data/README.md CHANGED
@@ -38,7 +38,23 @@ class Button < StateHolder
38
38
  # button methods here
39
39
  end
40
40
  ```
41
- If you want to set additional attributes at creation of a new button, new is called with an opts hash. Set the attribute from the opts hash in initialize. You *must* call super if you provide an initialize method in your holder class.
41
+
42
+ 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:
43
+
44
+ ```ruby
45
+ button = Button.new(initial_state_class: Off)
46
+ ```
47
+ or alternate syntax:
48
+
49
+ ```ruby
50
+ button = Button.new(start_in: Off)
51
+ ```
52
+ 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.
53
+
54
+ ```ruby
55
+ button = Button.new(start_in: Off, color: 'Red')
56
+ ```
57
+
42
58
 
43
59
  Inherit from State to create a class to provide specific state behaviors:
44
60
 
@@ -63,18 +79,13 @@ private
63
79
  end
64
80
  end
65
81
  ```
66
- The subclassed state may provide *private* enter and exit methods. Any other state methods intended to be available via a call to that method on the state holder must be public. #enter and #exit will always be called appropriately during state transitions.
82
+ The subclassed state may provide *private* enter and exit methods. Any other state methods intended to be available via a method call on the state holder must be public. #enter and #exit will always be called appropriately during state transitions.
67
83
 
68
84
  A state has access to methods on the state holder via #holder:
69
85
 
70
86
  ```ruby
71
87
  holder.a_special_holder_method
72
88
  ```
73
- Creation of a holder instance *must* specify the initial state class:
74
-
75
- ```ruby
76
- button = Button.new(initial_state_class: Off)
77
- ```
78
89
 
79
90
  The button module provides an example of the usage of Simplestate. Tests of this are provided in simplestate_test.rb.
80
91
 
@@ -1,9 +1,8 @@
1
1
  class StateHolder < SimpleDelegator
2
2
  def initialize(opts={})
3
- initial_state_class = opts.fetch :initial_state_class
4
- initial_state = initial_state_class.new(self, nil)
5
- # Set current_state within SimpleDelegator
6
- super(initial_state)
3
+ set_initial_state_from(opts)
4
+ # Set current_state to initial state within SimpleDelegator
5
+ super(@initial_state)
7
6
  end
8
7
 
9
8
  def transition_to(new_state_class)
@@ -25,4 +24,11 @@ private
25
24
  def current_state=(state)
26
25
  __setobj__(state)
27
26
  end
27
+
28
+ def set_initial_state_from(opts)
29
+ initial_state_class = opts.fetch :start_in,
30
+ (opts.fetch :initial_state_class, nil)
31
+ @initial_state = initial_state_class.new(self, nil)
32
+ end
33
+
28
34
  end
@@ -1,3 +1,3 @@
1
1
  module Simplestate
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
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: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell C Kuppinger