aasm 3.3.3 → 3.4.0

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: bfaa647a858b7edb82248c4eb3fc9ccc8ad25c3a
4
- data.tar.gz: ef830c2521b024474530bce0c814763cadfd7688
3
+ metadata.gz: 90aa17e423f74f9397944f3e941fc539833f4a86
4
+ data.tar.gz: c18f24941a1ed1c7880140decfe262a88b37f3aa
5
5
  SHA512:
6
- metadata.gz: 0651274c41ba3dbc905b8cab1e47a812d18e422d8c4045344c705a956246112e36e4bbb255c7107fbd03b8992504d4498b6c60c224dddd4bd6dca75372bcdeee
7
- data.tar.gz: c5ac9cc392993b3e416578d20fcacff1ddec041e48d4aebe37425e29475b7b882ed1fd5423f89d1f030c4bed53e816000ca189adc9a9f48b97373356552ae4f7
6
+ metadata.gz: de15b7a7878ba85fe1da7f7e55bb418b499a31c3a7f3556bd66be0667e077a7c69ca2f02ce8f5066b5274a98639ca4c101f94c28c9bc113a5ba14a70876bb4eb
7
+ data.tar.gz: 9d3fd63e5bec19aae9234bf8a13a889934fd97202e4c30cdf85bd518176034c95c81a8bbd623298d728d706c46c51086375f162a1364f6c69de90ce8642af5e0
@@ -4,6 +4,10 @@
4
4
 
5
5
  * deprecated old aasm_* class methods (old-style DSL), in preparation for AASM v4.0.0
6
6
 
7
+ ## 3.4.0
8
+
9
+ * allow retrieving the current event (`aasm.current_event`) (see [issue #159](https://github.com/aasm/aasm/issues/159) and [issue #168](https://github.com/aasm/aasm/issues/168))
10
+
7
11
  ## 3.3.3
8
12
 
9
13
  * bugfix: support reloading development environment in Rails (see [issue #148](https://github.com/aasm/aasm/issues/148))
data/README.md CHANGED
@@ -163,6 +163,31 @@ originating state (the from-state) and the target state (the to state), like thi
163
163
  end
164
164
  ```
165
165
 
166
+ #### The current event triggered
167
+
168
+ While running the callbacks you can easily retrieve the name of the event triggered
169
+ by using `aasm.current_event`:
170
+
171
+ ```ruby
172
+ # taken the example callback from above
173
+ def do_something
174
+ puts "triggered #{aasm.current_event}"
175
+ end
176
+ ```
177
+
178
+ and then
179
+
180
+ ```ruby
181
+ job = Job.new
182
+
183
+ # without bang
184
+ job.sleep # => triggered :sleep
185
+
186
+ # with bang
187
+ job.sleep! # => triggered :sleep!
188
+ ```
189
+
190
+
166
191
  ### Guards
167
192
 
168
193
  Let's assume you want to allow particular transitions only if a defined condition is
@@ -55,10 +55,12 @@ module AASM
55
55
  end
56
56
 
57
57
  @klass.send(:define_method, "#{name.to_s}!") do |*args, &block|
58
+ aasm.current_event = "#{name.to_s}!".to_sym
58
59
  aasm_fire_event(name, {:persist => true}, *args, &block)
59
60
  end
60
61
 
61
62
  @klass.send(:define_method, "#{name.to_s}") do |*args, &block|
63
+ aasm.current_event = name.to_sym
62
64
  aasm_fire_event(name, {:persist => false}, *args, &block)
63
65
  end
64
66
  end
@@ -1,7 +1,7 @@
1
1
  module AASM
2
2
  class InstanceBase
3
3
 
4
- attr_accessor :from_state, :to_state
4
+ attr_accessor :from_state, :to_state, :current_event
5
5
 
6
6
  def initialize(instance)
7
7
  @instance = instance
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "3.3.3"
2
+ VERSION = "3.4.0"
3
3
  end
@@ -244,6 +244,24 @@ describe 'should fire callbacks' do
244
244
  end
245
245
  end
246
246
 
247
+ describe 'current event' do
248
+ let(:pe) {ParametrisedEvent.new}
249
+
250
+ it 'if no event has been triggered' do
251
+ expect(pe.aasm.current_event).to be_nil
252
+ end
253
+
254
+ it 'if a event has been triggered' do
255
+ pe.wakeup
256
+ expect(pe.aasm.current_event).to eql :wakeup
257
+ end
258
+
259
+ it 'if no event has been triggered' do
260
+ pe.wakeup!
261
+ expect(pe.aasm.current_event).to eql :wakeup!
262
+ end
263
+ end
264
+
247
265
  describe 'parametrised events' do
248
266
  let(:pe) {ParametrisedEvent.new}
249
267
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.3
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Barron
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-08-20 00:00:00.000000000 Z
13
+ date: 2014-09-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake