end_state 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/end_state/state_machine.rb +6 -3
- data/lib/end_state/version.rb +1 -1
- data/spec/end_state/state_machine_spec.rb +11 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c199657701bb9dec215e09e17d5e3e27d1d95d3e
|
4
|
+
data.tar.gz: 240681ba88cc834317071327063867828e994af0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0728b393e7550ad3aa5833854b36c0c84089556c9e798c3ef9c9ac627989d48f4064225c9eedf8770bbdcc818f5991f37646ba3eaa4e784378cb0acebe37dd27
|
7
|
+
data.tar.gz: 5b4b5f3fd214558f7a1529015f23cea0ca12de44dc5c4c23663013d6cce49582c86c907dd5afda5816251a03430fc6861d78be36daf117e72fa743cca6042dd5
|
@@ -80,12 +80,11 @@ module EndState
|
|
80
80
|
|
81
81
|
def method_missing(method, *args, &block)
|
82
82
|
check_state = method.to_s[0..-2].to_sym
|
83
|
+
return current_state?(check_state) if method.to_s.end_with?('?')
|
83
84
|
check_state = state_for_event(check_state) || check_state
|
84
85
|
return false if check_state == :__invalid_event__
|
85
86
|
return super unless self.class.states.include?(check_state)
|
86
|
-
if method.to_s.end_with?('
|
87
|
-
state.to_sym == check_state
|
88
|
-
elsif method.to_s.end_with?('!')
|
87
|
+
if method.to_s.end_with?('!')
|
89
88
|
transition check_state, args[0]
|
90
89
|
else
|
91
90
|
super
|
@@ -94,6 +93,10 @@ module EndState
|
|
94
93
|
|
95
94
|
private
|
96
95
|
|
96
|
+
def current_state?(check_state)
|
97
|
+
state.to_sym == check_state
|
98
|
+
end
|
99
|
+
|
97
100
|
def state_for_event(event)
|
98
101
|
transitions = self.class.events[event]
|
99
102
|
return false unless transitions
|
data/lib/end_state/version.rb
CHANGED
@@ -130,6 +130,16 @@ module EndState
|
|
130
130
|
specify { expect(machine.b?).to be_true }
|
131
131
|
specify { expect(machine.a?).to be_false }
|
132
132
|
end
|
133
|
+
|
134
|
+
context 'when the state shares a name with an event' do
|
135
|
+
before { StateMachine.transition start: :stop, as: :stop }
|
136
|
+
|
137
|
+
context 'and the object, in that state, cannot transition on the event' do
|
138
|
+
let(:object) { OpenStruct.new(state: :stop) }
|
139
|
+
|
140
|
+
specify { expect(machine.stop?).to be_true }
|
141
|
+
end
|
142
|
+
end
|
133
143
|
end
|
134
144
|
|
135
145
|
describe '#{state}!' do
|
@@ -261,7 +271,7 @@ module EndState
|
|
261
271
|
it 'sends the guard the params' do
|
262
272
|
machine.transition :b, params, :soft
|
263
273
|
expect(guard).to have_received(:new).with(machine, :b, params)
|
264
|
-
end
|
274
|
+
end
|
265
275
|
end
|
266
276
|
end
|
267
277
|
|