simplestate 1.0.0 → 1.0.1

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: 3c899bf018689c01a33b5d830d07899ce62ec930
4
- data.tar.gz: f36c330f1c1e152f24573ceecbf1cdb55047c231
3
+ metadata.gz: 9458b96d5cc26eb1ec644c84d9f2ce011ba01105
4
+ data.tar.gz: 396329ac2d64a6f85f2b6b170b6d9bad41fa335d
5
5
  SHA512:
6
- metadata.gz: 0e9664a43777c82389fe56d9af35f3c3246d5e3b92de9850e3f7c188140c2ffae6b96c27594897cf02860d73feef0908c5b65c358d3f691592e6134df6e6f9a0
7
- data.tar.gz: d3a4ff105ccf61640de63c467b3f093e245695eda1b825719289a96263603c0c3a0ba4c429b696ad48f4a21676132b40d96abbd6adaaa3bd1790fad6a4ded15e
6
+ metadata.gz: 35400938a890b88dcbdf1008e03ddeec0936522730e26cdc6597ff80627607d9797711aa61420125a3a4e9411e17fb485acb7e38fd5492eac41b03e2efa5e62c
7
+ data.tar.gz: 98663723547abcdc086f8d45901be970f30769dc02807db78524aee175345ae1b68611cbbd9d22957b69194dc625b8522ee51e63fae0cb404cf70f490cf5297a
@@ -1,13 +1,8 @@
1
- class NilState
2
- attr_reader :holder
1
+ class NilState < State
3
2
  def initialize(holder)
4
- @holder = holder
5
3
  end
6
4
 
7
5
  private
8
- def transition_to(new_state_class)
9
- end
10
-
11
6
  def enter
12
7
  end
13
8
 
@@ -1,16 +1,12 @@
1
1
  class StateHolder < SimpleDelegator
2
- attr_reader :state_history
2
+ attr_reader :state_history, :beginning
3
3
  attr_accessor :hx_size_limit
4
4
  def initialize(opts={})
5
5
  @state_history = []
6
6
  @hx_size_limit = opts.fetch :hx_size_limit, 5
7
- # Set current_state to nil state within SimpleDelegator
8
- nil_state = NilState.new(nil)
9
- super(nil_state)
10
- # Then transition to the initial state class
11
- initial_state_class = opts.fetch :start_in,
12
- (opts.fetch :initial_state_class, nil)
13
- transition_to initial_state_class
7
+ @beginning = initial_state_class(opts)
8
+ super(NilState.new(nil))
9
+ transition_to beginning
14
10
  end
15
11
 
16
12
  def transition_to(new_state_class)
@@ -25,8 +21,7 @@ class StateHolder < SimpleDelegator
25
21
  end
26
22
 
27
23
  def set_new_state(new_state_class)
28
- new_state = new_state_class.new(self)
29
- self.current_state = new_state
24
+ self.current_state = new_state_class.new(self)
30
25
  end
31
26
 
32
27
  private
@@ -38,4 +33,10 @@ private
38
33
  @state_history << current_state
39
34
  @state_history = @state_history.last(hx_size_limit)
40
35
  end
36
+
37
+ def initial_state_class(opts)
38
+ isc = opts.fetch :start_in,
39
+ (opts.fetch :initial_state_class, nil)
40
+ isc ? isc : raise(NoMethodError)
41
+ end
41
42
  end
@@ -1,3 +1,3 @@
1
1
  module Simplestate
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
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.0
4
+ version: 1.0.1
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-01-31 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler