aasm 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +6 -4
- data/README_FROM_VERSION_3_TO_4.md +1 -1
- data/lib/aasm/aasm.rb +8 -4
- data/lib/aasm/base.rb +5 -0
- data/lib/aasm/event.rb +9 -9
- data/lib/aasm/version.rb +1 -1
- data/spec/unit/callbacks_spec.rb +2 -2
- data/spec/unit/event_spec.rb +1 -1
- data/spec/unit/localizer_spec.rb +6 -6
- 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: 1018c5f3c99b9124aa39e379ad07d1edc8e1a41a
|
4
|
+
data.tar.gz: c0f9d694a94587e857dddb747cf5eebbcec6a8e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 559fbc728a655f88f10b979ea74985c72b2705a663fd3c0b42b04cb2cc92d07c4ab65e791bc44972cb5d192030e30184e2376f6b1301ec3c28d0d612cf443f19
|
7
|
+
data.tar.gz: e13c9a34e666e1a03f3f7474347ca5c4da39a55649a1b34dcc2d38f97d02b84e98e439dc74324a0487a385ae6e5e9eb29570129832800042b25561f9595033b8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 4.1.0 (not yet released)
|
4
|
+
|
5
|
+
* `aasm_human_event_name` is deprecated, use `aasm.human_event_name` instead
|
6
|
+
|
7
|
+
## 4.0.1
|
8
|
+
|
9
|
+
* fire guards only once per transition (see [issue #184](https://github.com/aasm/aasm/issues/184) for details)
|
10
|
+
|
3
11
|
## 4.0.0
|
4
12
|
|
5
13
|
* support `if` and `unless` guard syntax: (see [issue #179](https://github.com/aasm/aasm/issues/179) and [issue #181](https://github.com/aasm/aasm/issues/181)), thanks to [@bigtunacan](https://github.com/bigtunacan)
|
data/Gemfile
CHANGED
@@ -5,7 +5,7 @@ gem "coveralls", :platforms => :ruby
|
|
5
5
|
gem 'rubysl', :platforms => :rbx
|
6
6
|
gem "jruby-openssl", :platforms => :jruby
|
7
7
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
8
|
-
gem "rails", "
|
8
|
+
gem "rails", "~>4.1"
|
9
9
|
gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
10
10
|
gem 'sequel'
|
11
11
|
|
data/README.md
CHANGED
@@ -13,6 +13,10 @@ that no longer targets only ActiveRecord models. It currently provides adapters
|
|
13
13
|
[Mongoid](http://mongoid.org/), but it can be used for any Ruby class, no matter what
|
14
14
|
parent class it has (if any).
|
15
15
|
|
16
|
+
## Upgrade from version 3 to 4
|
17
|
+
|
18
|
+
Take a look at the [README_FROM_VERSION_3_TO_4](https://github.com/aasm/aasm/blob/master/README_FROM_VERSION_3_TO_4.md) for details how to switch from version 3.x to 4.0 of _AASM_.
|
19
|
+
|
16
20
|
## Usage
|
17
21
|
|
18
22
|
Adding a state machine is as simple as including the AASM module and start defining
|
@@ -137,14 +141,12 @@ Here you can see a list of all possible callbacks, together with their order of
|
|
137
141
|
```ruby
|
138
142
|
begin
|
139
143
|
event before
|
140
|
-
event guards
|
141
|
-
transition guards
|
144
|
+
event guards
|
145
|
+
transition guards
|
142
146
|
old_state before_exit
|
143
147
|
old_state exit
|
144
148
|
new_state before_enter
|
145
149
|
new_state enter
|
146
|
-
event guards
|
147
|
-
transition guards
|
148
150
|
...update state...
|
149
151
|
transition after
|
150
152
|
event success # if persist successful
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
### Callback order has been changed
|
6
6
|
|
7
|
-
The first callback to be run is `:before` of the event. A state's `:before_exit
|
7
|
+
The first callback to be run is `:before` of the event. A state's `:before_exit` callback
|
8
8
|
is now run directly before its `:exit` callback. Event-based guards are now run before
|
9
9
|
any of the transition guards are run. And finally, before running any state callbacks,
|
10
10
|
all (event- and transition-based) guards are run to check whether the state callbacks
|
data/lib/aasm/aasm.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module AASM
|
2
2
|
|
3
|
+
# provide a state machine for the including class
|
4
|
+
# make sure to load class methods as well
|
5
|
+
# initialize persistence for the state machine
|
3
6
|
def self.included(base) #:nodoc:
|
4
7
|
base.extend AASM::ClassMethods
|
5
8
|
|
@@ -26,9 +29,10 @@ module AASM
|
|
26
29
|
@aasm
|
27
30
|
end
|
28
31
|
|
29
|
-
#
|
32
|
+
# deprecated, remove in version 4.1
|
30
33
|
def aasm_human_event_name(event) # event_name?
|
31
|
-
AASM
|
34
|
+
warn '[DEPRECATION] AASM: aasm_human_event_name is deprecated, use aasm.human_event_name instead'
|
35
|
+
aasm.human_event_name(event)
|
32
36
|
end
|
33
37
|
end # ClassMethods
|
34
38
|
|
@@ -82,11 +86,11 @@ private
|
|
82
86
|
*process_args(event, aasm.current_state, *args)
|
83
87
|
)
|
84
88
|
|
85
|
-
if event.may_fire?(self, *args)
|
89
|
+
if may_fire_to = event.may_fire?(self, *args)
|
86
90
|
old_state.fire_callbacks(:before_exit, self)
|
87
91
|
old_state.fire_callbacks(:exit, self) # TODO: remove for AASM 4?
|
88
92
|
|
89
|
-
if new_state_name = event.fire(self, *args)
|
93
|
+
if new_state_name = event.fire(self, {:may_fire => may_fire_to}, *args)
|
90
94
|
aasm_fired(event, old_state, new_state_name, options, *args, &block)
|
91
95
|
else
|
92
96
|
aasm_failed(event_name, old_state)
|
data/lib/aasm/base.rb
CHANGED
@@ -85,6 +85,11 @@ module AASM
|
|
85
85
|
@state_machine.events.values
|
86
86
|
end
|
87
87
|
|
88
|
+
# aasm.event(:event_name).human?
|
89
|
+
def human_event_name(event) # event_name?
|
90
|
+
AASM::Localizer.new.human_event_name(@klass, event)
|
91
|
+
end
|
92
|
+
|
88
93
|
def states_for_select
|
89
94
|
states.map { |state| state.for_select }
|
90
95
|
end
|
data/lib/aasm/event.rb
CHANGED
@@ -19,11 +19,11 @@ module AASM
|
|
19
19
|
# executes the transition guards to determine if a transition is even
|
20
20
|
# an option given current conditions.
|
21
21
|
def may_fire?(obj, to_state=nil, *args)
|
22
|
-
_fire(obj, true, to_state, *args) # true indicates test firing
|
22
|
+
_fire(obj, {:test_only => true}, to_state, *args) # true indicates test firing
|
23
23
|
end
|
24
24
|
|
25
|
-
def fire(obj, to_state=nil, *args)
|
26
|
-
_fire(obj,
|
25
|
+
def fire(obj, options={}, to_state=nil, *args)
|
26
|
+
_fire(obj, options, to_state, *args) # false indicates this is not a test (fire!)
|
27
27
|
end
|
28
28
|
|
29
29
|
def transitions_from_state?(state)
|
@@ -86,8 +86,8 @@ module AASM
|
|
86
86
|
end
|
87
87
|
|
88
88
|
# Execute if test == false, otherwise return true/false depending on whether it would fire
|
89
|
-
def _fire(obj,
|
90
|
-
result =
|
89
|
+
def _fire(obj, options={}, to_state=nil, *args)
|
90
|
+
result = options[:test_only] ? false : nil
|
91
91
|
if @transitions.map(&:from).any?
|
92
92
|
transitions = @transitions.select { |t| t.from == obj.aasm.current_state }
|
93
93
|
return result if transitions.size == 0
|
@@ -106,11 +106,11 @@ module AASM
|
|
106
106
|
|
107
107
|
transitions.each do |transition|
|
108
108
|
next if to_state and !Array(transition.to).include?(to_state)
|
109
|
-
if transition.allowed?(obj, *args)
|
110
|
-
|
111
|
-
|
109
|
+
if Array(transition.to).include?(options[:may_fire]) || transition.allowed?(obj, *args)
|
110
|
+
result = to_state || Array(transition.to).first
|
111
|
+
if options[:test_only]
|
112
|
+
# result = true
|
112
113
|
else
|
113
|
-
result = to_state || Array(transition.to).first
|
114
114
|
transition.execute(obj, *args)
|
115
115
|
end
|
116
116
|
|
data/lib/aasm/version.rb
CHANGED
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -11,8 +11,8 @@ describe 'callbacks for the new DSL' do
|
|
11
11
|
expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
12
12
|
expect(callback).to receive(:before_exit_open).once.ordered # these should be before the state changes
|
13
13
|
expect(callback).to receive(:exit_open).once.ordered
|
14
|
-
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
15
|
-
expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
14
|
+
# expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
15
|
+
# expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
16
16
|
expect(callback).to receive(:transitioning).once.ordered
|
17
17
|
expect(callback).to receive(:before_enter_closed).once.ordered
|
18
18
|
expect(callback).to receive(:enter_closed).once.ordered
|
data/spec/unit/event_spec.rb
CHANGED
@@ -101,7 +101,7 @@ describe 'firing an event' do
|
|
101
101
|
obj = double('object', :aasm => double('aasm', :current_state => :open))
|
102
102
|
expect(obj).to receive(:guard_fn).with('arg1', 'arg2').and_return(true)
|
103
103
|
|
104
|
-
expect(event.fire(obj, nil, 'arg1', 'arg2')).to eq(:closed)
|
104
|
+
expect(event.fire(obj, {}, nil, 'arg1', 'arg2')).to eq(:closed)
|
105
105
|
end
|
106
106
|
|
107
107
|
end
|
data/spec/unit/localizer_spec.rb
CHANGED
@@ -67,13 +67,13 @@ describe AASM::Localizer, "new style" do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
context '
|
70
|
+
context 'aasm.human_event_name' do
|
71
71
|
it 'should return translated event name' do
|
72
|
-
expect(LocalizerTestModel.
|
72
|
+
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'should return humanized event name' do
|
76
|
-
expect(LocalizerTestModel.
|
76
|
+
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -102,13 +102,13 @@ describe AASM::Localizer, "deprecated style" do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
context '
|
105
|
+
context 'aasm.human_event_name' do
|
106
106
|
it 'should return translated event name' do
|
107
|
-
expect(LocalizerTestModel.
|
107
|
+
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'should return humanized event name' do
|
111
|
-
expect(LocalizerTestModel.
|
111
|
+
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
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: 4.0.
|
4
|
+
version: 4.0.1
|
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-11-
|
13
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|