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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +25 -0
- data/lib/aasm/base.rb +2 -0
- data/lib/aasm/instance_base.rb +1 -1
- data/lib/aasm/version.rb +1 -1
- data/spec/unit/event_spec.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90aa17e423f74f9397944f3e941fc539833f4a86
|
4
|
+
data.tar.gz: c18f24941a1ed1c7880140decfe262a88b37f3aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de15b7a7878ba85fe1da7f7e55bb418b499a31c3a7f3556bd66be0667e077a7c69ca2f02ce8f5066b5274a98639ca4c101f94c28c9bc113a5ba14a70876bb4eb
|
7
|
+
data.tar.gz: 9d3fd63e5bec19aae9234bf8a13a889934fd97202e4c30cdf85bd518176034c95c81a8bbd623298d728d706c46c51086375f162a1364f6c69de90ce8642af5e0
|
data/CHANGELOG.md
CHANGED
@@ -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
|
data/lib/aasm/base.rb
CHANGED
@@ -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
|
data/lib/aasm/instance_base.rb
CHANGED
data/lib/aasm/version.rb
CHANGED
data/spec/unit/event_spec.rb
CHANGED
@@ -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.
|
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-
|
13
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|