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 +4 -4
- data/lib/simplestate/nil_state.rb +1 -6
- data/lib/simplestate/state_holder.rb +11 -10
- 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: 9458b96d5cc26eb1ec644c84d9f2ce011ba01105
|
|
4
|
+
data.tar.gz: 396329ac2d64a6f85f2b6b170b6d9bad41fa335d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35400938a890b88dcbdf1008e03ddeec0936522730e26cdc6597ff80627607d9797711aa61420125a3a4e9411e17fb485acb7e38fd5492eac41b03e2efa5e62c
|
|
7
|
+
data.tar.gz: 98663723547abcdc086f8d45901be970f30769dc02807db78524aee175345ae1b68611cbbd9d22957b69194dc625b8522ee51e63fae0cb404cf70f490cf5297a
|
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
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.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-
|
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|