juncture 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/juncture.rb +7 -8
- data/lib/juncture/version.rb +2 -2
- data/spec/juncture_spec.rb +72 -92
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfbc1fc326d6601300f5eb27f6bec268fb8e8e38
|
4
|
+
data.tar.gz: 8b34ea800a6c03e0a8faf8db8f11b6b1875d3de3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b65cbd6412036d639bcd012b0a494cde8e96e513ee37ccd3163424341c236ddd487437cf7844843ad0d80206f9b8d2b72ef8a5857fadc9a51691a82ed163e85
|
7
|
+
data.tar.gz: b9cbffdd404fee593417cb61ff26c3f5fa4258079c73e2596ad8a294d96bb3d9f004b56a007829d9c666b7d69d993d51af16c9fa0c6963bc78e20aa86a1afffe
|
data/lib/juncture.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
class Juncture
|
2
|
-
attr_reader :states
|
3
|
-
|
4
2
|
def initialize *states, **kwargs
|
5
3
|
@states = states
|
6
4
|
@current_state = kwargs[:default]
|
@@ -26,6 +24,7 @@ class Juncture
|
|
26
24
|
raise "UNKNOWN STATE: %s" % new_state unless @states.include? new_state
|
27
25
|
@current_state = new_state
|
28
26
|
end
|
27
|
+
alias_method :is, :set
|
29
28
|
|
30
29
|
def next
|
31
30
|
if index.nil? || @states[index+1].nil?
|
@@ -44,24 +43,24 @@ class Juncture
|
|
44
43
|
end
|
45
44
|
|
46
45
|
def <(value)
|
47
|
-
index
|
46
|
+
@states[index+1..-1].include? value
|
48
47
|
end
|
49
48
|
|
50
49
|
def <=(value)
|
51
|
-
index
|
50
|
+
@states[index..-1].include? value
|
52
51
|
end
|
53
52
|
|
54
53
|
def >(value)
|
55
|
-
index
|
54
|
+
@states[0..index-1].include? value
|
56
55
|
end
|
57
56
|
|
58
57
|
def >=(value)
|
59
|
-
index
|
58
|
+
@states[0..index].include? value
|
60
59
|
end
|
61
60
|
|
62
61
|
private
|
63
62
|
|
64
|
-
def index
|
65
|
-
@states.index(
|
63
|
+
def index
|
64
|
+
@states.index(@current_state)
|
66
65
|
end
|
67
66
|
end
|
data/lib/juncture/version.rb
CHANGED
data/spec/juncture_spec.rb
CHANGED
@@ -6,177 +6,157 @@ describe Juncture do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe '::new' do
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
it 'creates a new instance of Juncture' do
|
10
|
+
expect(Juncture.new []).to be_an_instance_of Juncture
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#inspect' do
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
it 'returns the Juncture object' do
|
16
|
+
expect(Juncture.new([]).inspect).to match(/<Juncture:\S+ State:\S*>/)
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '#state' do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
it 'returns the current state' do
|
22
|
+
temp = Juncture.new 1, 2, 3
|
23
|
+
expect(temp.state).to be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the default state' do
|
27
|
+
temp = Juncture.new 1, 2, 3, default: 1
|
28
|
+
expect(temp.state).to eq 1
|
29
|
+
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe '#set' do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
it 'sets the current state' do
|
34
|
+
temp = Juncture.new 1, 2, 3
|
35
|
+
temp.set 1
|
36
|
+
expect(temp.state).to eq 1
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'raises an error if the state is not present' do
|
40
|
+
temp = Juncture.new 1, 2, 3
|
41
|
+
expect{ temp.set 4 }.to raise_error
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe '#next' do
|
46
46
|
it 'moves the state forward one step' do
|
47
|
-
temp = Juncture.new
|
48
|
-
expect(temp.next).to eq
|
49
|
-
expect(temp.state).to eq
|
50
|
-
expect(temp.next).to eq
|
51
|
-
expect(temp.state).to eq
|
47
|
+
temp = Juncture.new 1, 2, 3, default: 1
|
48
|
+
expect(temp.next).to eq 2
|
49
|
+
expect(temp.state).to eq 2
|
50
|
+
expect(temp.next).to eq 3
|
51
|
+
expect(temp.state).to eq 3
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'resets if on final state' do
|
55
|
-
temp = Juncture.new
|
56
|
-
expect(temp.next).to eq
|
57
|
-
expect(temp.state).to eq
|
58
|
-
expect(temp.next).to eq
|
59
|
-
expect(temp.state).to eq
|
55
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
56
|
+
expect(temp.next).to eq 3
|
57
|
+
expect(temp.state).to eq 3
|
58
|
+
expect(temp.next).to eq 1
|
59
|
+
expect(temp.state).to eq 1
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'resets if default is nil' do
|
63
|
-
temp = Juncture.new
|
64
|
-
expect(temp.next).to eq
|
65
|
-
expect(temp.state).to eq
|
66
|
-
expect(temp.next).to eq
|
67
|
-
expect(temp.state).to eq
|
63
|
+
temp = Juncture.new 1, 2, 3
|
64
|
+
expect(temp.next).to eq 1
|
65
|
+
expect(temp.state).to eq 1
|
66
|
+
expect(temp.next).to eq 2
|
67
|
+
expect(temp.state).to eq 2
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'resets if default is not a state' do
|
71
|
-
temp = Juncture.new
|
72
|
-
expect(temp.next).to eq
|
73
|
-
expect(temp.state).to eq
|
74
|
-
expect(temp.next).to eq
|
75
|
-
expect(temp.state).to eq
|
71
|
+
temp = Juncture.new 1, 2, 3, default: 4
|
72
|
+
expect(temp.next).to eq 1
|
73
|
+
expect(temp.state).to eq 1
|
74
|
+
expect(temp.next).to eq 2
|
75
|
+
expect(temp.state).to eq 2
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe '#==' do
|
80
80
|
it 'returns true if matching' do
|
81
|
-
temp = Juncture.new
|
82
|
-
expect(temp ==
|
81
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
82
|
+
expect(temp == 2).to be_true
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'returns false if not matching' do
|
86
|
-
temp = Juncture.new
|
87
|
-
expect(temp ==
|
86
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
87
|
+
expect(temp == 1).to be_false
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
describe '#===' do
|
92
92
|
it 'returns true if matching' do
|
93
|
-
temp = Juncture.new
|
94
|
-
expect(temp ===
|
93
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
94
|
+
expect(temp === 2).to be_true
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'returns false if not matching' do
|
98
|
-
temp = Juncture.new
|
99
|
-
expect(temp ===
|
98
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
99
|
+
expect(temp === 1).to be_false
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
describe '#<' do
|
104
104
|
it 'returns true if matching' do
|
105
|
-
temp = Juncture.new
|
106
|
-
expect(temp <
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'returns false if not matching' do
|
110
|
-
temp = Juncture.new :first, :second, :third, default: :second
|
111
|
-
expect(temp < :second).to be_false
|
105
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
106
|
+
expect(temp < 3).to be_true
|
112
107
|
end
|
113
108
|
|
114
109
|
it 'returns false if not matching' do
|
115
|
-
temp = Juncture.new
|
116
|
-
expect(temp <
|
110
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
111
|
+
expect(temp < 2).to be_false
|
117
112
|
end
|
118
113
|
end
|
119
114
|
|
120
115
|
describe '#<=' do
|
121
116
|
it 'returns true if matching' do
|
122
|
-
temp = Juncture.new
|
123
|
-
expect(temp <=
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'returns true if matching' do
|
127
|
-
temp = Juncture.new :first, :second, :third, default: :second
|
128
|
-
expect(temp <= :second).to be_true
|
117
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
118
|
+
expect(temp <= 2).to be_true
|
129
119
|
end
|
130
120
|
|
131
121
|
it 'returns false if not matching' do
|
132
|
-
temp = Juncture.new
|
133
|
-
expect(temp <=
|
122
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
123
|
+
expect(temp <= 1).to be_false
|
134
124
|
end
|
135
125
|
end
|
136
126
|
|
137
127
|
describe '#>' do
|
138
128
|
it 'returns true if matching' do
|
139
|
-
temp = Juncture.new
|
140
|
-
expect(temp >
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'returns false if not matching' do
|
144
|
-
temp = Juncture.new :first, :second, :third, default: :second
|
145
|
-
expect(temp > :second).to be_false
|
129
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
130
|
+
expect(temp > 1).to be_true
|
146
131
|
end
|
147
132
|
|
148
133
|
it 'returns false if not matching' do
|
149
|
-
temp = Juncture.new
|
150
|
-
expect(temp >
|
134
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
135
|
+
expect(temp > 2).to be_false
|
151
136
|
end
|
152
137
|
end
|
153
138
|
|
154
139
|
describe '#>=' do
|
155
140
|
it 'returns true if matching' do
|
156
|
-
temp = Juncture.new
|
157
|
-
expect(temp >=
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'returns true if matching' do
|
161
|
-
temp = Juncture.new :first, :second, :third, default: :second
|
162
|
-
expect(temp >= :second).to be_true
|
141
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
142
|
+
expect(temp >= 2).to be_true
|
163
143
|
end
|
164
144
|
|
165
145
|
it 'returns false if not matching' do
|
166
|
-
temp = Juncture.new
|
167
|
-
expect(temp >=
|
146
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
147
|
+
expect(temp >= 3).to be_false
|
168
148
|
end
|
169
149
|
end
|
170
150
|
|
171
151
|
describe '#method_missing' do
|
172
152
|
it 'forards to the state array' do
|
173
|
-
temp = Juncture.new
|
174
|
-
expect(temp[1]).to eq
|
153
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
154
|
+
expect(temp[1]).to eq 2
|
175
155
|
expect(temp.length).to eq 3
|
176
156
|
end
|
177
157
|
|
178
158
|
it 'raises an error to super' do
|
179
|
-
temp = Juncture.new
|
159
|
+
temp = Juncture.new 1, 2, 3, default: 2
|
180
160
|
expect{ temp.no_response }.to raise_error
|
181
161
|
end
|
182
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: juncture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Slaughter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -72,10 +72,10 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
-
- README.md
|
76
75
|
- LICENSE
|
77
|
-
-
|
76
|
+
- README.md
|
78
77
|
- lib/juncture.rb
|
78
|
+
- lib/juncture/version.rb
|
79
79
|
- spec/juncture_spec.rb
|
80
80
|
- spec/spec_helper.rb
|
81
81
|
homepage: http://benslaughter.github.io/juncture/
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.2.2
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: Simple state object
|