state_design_pattern 0.0.1 → 0.0.2
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 +8 -8
- data/README.md +2 -1
- data/lib/state_design_pattern/state_machine.rb +6 -4
- data/lib/state_design_pattern/version.rb +1 -1
- data/spec/state_design_pattern_spec.rb +6 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWIzZTVjMDcyYmY2NTZiYTNmNTlkMDEyZGI2OWIyZDQwMTliYjA4YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjdiMjlkZDI5OTdlM2MxMjZiNTQyODM2YmFjNTU4NDI0ZDQ0MmIwMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzQwYWNiZjcwNTRjY2NkOTJjZmJlNjAyYjBlNDkwMDBlNjUwYWNjOWE0YTJh
|
10
|
+
YmY4ZGNiNmI4YzQ5ZjMyZjU3ODdiODA2MTM0NDdjYTMxNDc4ZDc0Mjg0NzI5
|
11
|
+
NTRmN2YzMTU2OWQ4ZDgyZmZiYWQwNTNkNGExYjY1N2NlOTUxNTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjIwZDA0MzUyYTMzMjk2MDViZWNkMDVkMzJhNjZkZThiMjNlMjEwMDY1MjZi
|
14
|
+
OTgzMjM3NDMxMDdiMzAyZjY5NDc3MWI4MTZkMzBhOWEyMDQxNWE5YTQ4YjQ5
|
15
|
+
Y2VkYjQ5MjM0NmM1NDIwMzQ3MzY0NGZlNGIxOTAwYzY5YTA5NTE=
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# state_design_pattern
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/state_design_pattern)
|
3
4
|
[](https://travis-ci.org/dwayne/state_design_pattern)
|
4
|
-
[](https://coveralls.io/r/dwayne/state_design_pattern)
|
5
|
+
[](https://coveralls.io/r/dwayne/state_design_pattern?branch=master)
|
5
6
|
[](https://codeclimate.com/github/dwayne/state_design_pattern)
|
6
7
|
|
7
8
|
An implementation of the
|
@@ -7,6 +7,8 @@ module StateDesignPattern
|
|
7
7
|
extend Forwardable
|
8
8
|
include Observable
|
9
9
|
|
10
|
+
attr_reader :context
|
11
|
+
|
10
12
|
def initialize
|
11
13
|
initialize_context
|
12
14
|
transition_to_start_state
|
@@ -45,7 +47,7 @@ module StateDesignPattern
|
|
45
47
|
private
|
46
48
|
|
47
49
|
def initialize_context
|
48
|
-
@
|
50
|
+
@context = initial_context
|
49
51
|
end
|
50
52
|
|
51
53
|
def transition_to_start_state
|
@@ -58,9 +60,9 @@ module StateDesignPattern
|
|
58
60
|
end
|
59
61
|
|
60
62
|
def setup_context_delegation
|
61
|
-
if @
|
62
|
-
methods = @
|
63
|
-
self.class.def_delegators :@
|
63
|
+
if @context
|
64
|
+
methods = @context.members.map { |reader| [reader, "#{reader}=".to_sym] }.flatten
|
65
|
+
self.class.def_delegators :@context, *methods
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
@@ -10,9 +10,11 @@ describe "the operation of the state design pattern with an example" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def initial_context
|
13
|
-
Struct
|
14
|
-
|
15
|
-
|
13
|
+
Struct.new(:energy, :times_on, :times_off) do
|
14
|
+
def blown?
|
15
|
+
energy < 25
|
16
|
+
end
|
17
|
+
end.new(100, 0, 0)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -35,7 +37,7 @@ describe "the operation of the state design pattern with an example" do
|
|
35
37
|
class Off < Switch
|
36
38
|
|
37
39
|
def turn_on
|
38
|
-
if state_machine.
|
40
|
+
if !state_machine.context.blown?
|
39
41
|
state_machine.energy -= 25
|
40
42
|
state_machine.times_on += 1
|
41
43
|
state_machine.transition_to_state_and_send_event(On, :turned_on, when: TIMESTAMP)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_design_pattern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dwayne R. Crooks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|