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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae3d305a090f889c3ec8c4f8cd9aa7746195e047
4
- data.tar.gz: 51e2c2b4850c6a6831785999720073b336e03d15
3
+ metadata.gz: c199657701bb9dec215e09e17d5e3e27d1d95d3e
4
+ data.tar.gz: 240681ba88cc834317071327063867828e994af0
5
5
  SHA512:
6
- metadata.gz: 0438d6dd04ca45c009d0087ace06af294ce87db794fcbc1b44691d36f1f760343cd8ace467013663d509a7cc2330a8c28ad2c8781699d473c264667733e58380
7
- data.tar.gz: a0b3c8565c86b8894acc121c2c9412a45ef299a7e2749e3d9e8d3f335b58197dadf364e7980fdc2d3187c5d349ffbe6e873b40268265c7519597ef3768f5f196
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
@@ -1,3 +1,3 @@
1
1
  module EndState
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: end_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - alexpeachey