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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b88600a7f311b9c2b85581f4eb88a723ffec79a
4
- data.tar.gz: 2557d44569ccd323304f8faab7bbf2970be3f529
3
+ metadata.gz: db5428361e6e4a05f7b412039b9d2d4573d0347a
4
+ data.tar.gz: 32e57aa972d3dc98978d67091a60be22094151a1
5
5
  SHA512:
6
- metadata.gz: 380a5239dfa7ce6168cba6f5603eb22d5fd905a2a3acd06dc4ae4b5f4e480bbdfbf3de69da5c480d0adcbf75c585a8c83bdf02e7a504afbcb4554e974a921344
7
- data.tar.gz: 6095ed9e3290016f296d794da764ec17e13c125e60af33a4cf5a31c11df324596eef3e164d4549f3ef3b66bac34e725f96c87545cc2469c96bcb734c7c5546ad
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
@@ -3,5 +3,9 @@ source 'https://rubygems.org'
3
3
  #gem 'coveralls', require: false
4
4
  gem "codeclimate-test-reporter", group: :test, require: nil
5
5
 
6
+ #gem "pry"
7
+ #gem "pry-byebug"
8
+
9
+
6
10
  # Specify your gem's dependencies in simplestate.gemspec
7
11
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simplestate (2.0.5)
4
+ simplestate (2.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  ```ruby
8
8
  class Button < StateHolder
9
9
  attr_reader :name
10
- def initialize(initial_state: :Off, state_history: StateHistory.new, opts: {})
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( initial_state: :Off, opts: {} )
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 *must* 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.:
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( initial_state: :Off,
128
- opts: {color: 'Red'} )
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/dummys/button.rb) provides an example of the usage of Simplestate. Tests of this are provided in button\_test.rb.
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: nil, opts: {})
6
+ def initialize(holder:, opts: {})
7
7
  @holder = holder
8
- end
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, :state_history
2
+ attr_reader :initial_state
3
3
 
4
- def initialize(initial_state:, state_history: StateHistory.new, opts: {})
5
- @initial_state = initial_state
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 = StateList.new
8
-
9
- super(NullState.new)
9
+ @state_list = state_list
10
+ super
10
11
  end
11
12
 
12
- def start
13
- state_history << current_state.symbol
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
@@ -1,3 +1,3 @@
1
1
  module Simplestate
2
- VERSION = "2.0.6"
2
+ VERSION = "2.0.7"
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: 2.0.6
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-10 00:00:00.000000000 Z
11
+ date: 2016-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler