aasm 3.0.19 → 3.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -7
- data/README.md +20 -4
- data/lib/aasm/aasm.rb +4 -0
- data/lib/aasm/base.rb +6 -0
- data/lib/aasm/event.rb +3 -3
- data/lib/aasm/persistence/base.rb +1 -1
- data/lib/aasm/version.rb +1 -1
- data/spec/models/mongoid/no_scope_mongoid.rb +10 -0
- data/spec/models/persistence.rb +7 -0
- data/spec/schema.rb +1 -1
- data/spec/unit/persistence/active_record_persistence_spec.rb +4 -0
- data/spec/unit/persistence/mongoid_persistance_spec.rb +4 -0
- metadata +76 -24
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.0.20
|
4
|
+
|
5
|
+
* added configuration option to disable automatic scope creation
|
6
|
+
|
3
7
|
## 3.0.19
|
4
8
|
|
5
|
-
* fixed deprecation warning with Rails 4 (Relation#update_all with conditions is deprecated)
|
6
|
-
* fixing issue #69 (ActiveRecord scopes are not chainable)
|
9
|
+
* fixed deprecation warning with *Rails 4* (`Relation#update_all` with conditions is deprecated)
|
10
|
+
* fixing [issue #69](https://github.com/aasm/aasm/issues/69) ( *ActiveRecord* scopes are not chainable)
|
7
11
|
|
8
12
|
## 3.0.18
|
9
13
|
|
10
|
-
* fixing issue #66 (state methods not reflecting the current state)
|
14
|
+
* fixing [issue #66](https://github.com/aasm/aasm/issues/66) (state methods not reflecting the current state)
|
11
15
|
|
12
16
|
## 3.0.17
|
13
17
|
|
14
|
-
* supporting instance level inspection for states (including permissible state, see issue #54)
|
18
|
+
* supporting instance level inspection for states (including permissible state, see [issue #54](https://github.com/aasm/aasm/issues/54))
|
15
19
|
* added autocreation of constants for each state ([@jherdman](https://github.com/jherdman))
|
16
20
|
|
17
21
|
## 3.0.16
|
@@ -20,7 +24,7 @@
|
|
20
24
|
|
21
25
|
## 3.0.15
|
22
26
|
|
23
|
-
* added support for localized state names (on a class level, like Record.aasm.states.map(&:localized_name))
|
27
|
+
* added support for localized state names (on a class level, like `Record.aasm.states.map(&:localized_name)`)
|
24
28
|
|
25
29
|
## 3.0.14
|
26
30
|
|
@@ -40,7 +44,7 @@
|
|
40
44
|
|
41
45
|
## 3.0.10
|
42
46
|
|
43
|
-
* added support for transitions from all other states (thanks to
|
47
|
+
* added support for transitions from all other states (thanks to [@swrobel](https://github.com/swrobel))
|
44
48
|
|
45
49
|
## 3.0.9
|
46
50
|
|
@@ -52,7 +56,7 @@
|
|
52
56
|
|
53
57
|
## 3.0.7
|
54
58
|
|
55
|
-
* removed deprecation warning when localizing aasm state names (look at https://github.com/rubyist/aasm/issues/38 for details)
|
59
|
+
* removed deprecation warning when localizing aasm state names (look at [issue #38](https://github.com/rubyist/aasm/issues/38) for details)
|
56
60
|
|
57
61
|
## 3.0.6
|
58
62
|
|
data/README.md
CHANGED
@@ -268,6 +268,22 @@ class JobsController < ApplicationController
|
|
268
268
|
end
|
269
269
|
```
|
270
270
|
|
271
|
+
If you don't need scopes (or simply don't want them), disable their creation when
|
272
|
+
defining the `AASM` states, like this:
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
class Job < ActiveRecord::Base
|
276
|
+
include AASM
|
277
|
+
|
278
|
+
aasm :create_scopes => false do
|
279
|
+
state :sleeping, :initial => true
|
280
|
+
state :running
|
281
|
+
state :cleaning
|
282
|
+
end
|
283
|
+
end
|
284
|
+
```
|
285
|
+
|
286
|
+
|
271
287
|
### Transaction support
|
272
288
|
|
273
289
|
Since version *3.0.13* AASM supports ActiveRecord transactions. So whenever a transition
|
@@ -313,16 +329,16 @@ Given the `Job` class from above:
|
|
313
329
|
```ruby
|
314
330
|
job = Job.new
|
315
331
|
|
316
|
-
job.states
|
332
|
+
job.aasm.states
|
317
333
|
=> [:sleeping, :running, :cleaning]
|
318
334
|
|
319
|
-
job.states(:permissible => true)
|
335
|
+
job.aasm.states(:permissible => true)
|
320
336
|
=> [:running]
|
321
337
|
job.run
|
322
|
-
job.states(:permissible => true)
|
338
|
+
job.aasm.states(:permissible => true)
|
323
339
|
=> [:cleaning, :sleeping]
|
324
340
|
|
325
|
-
job.events
|
341
|
+
job.aasm.events
|
326
342
|
=> [:run, :clean, :sleep]
|
327
343
|
```
|
328
344
|
|
data/lib/aasm/aasm.rb
CHANGED
@@ -2,7 +2,11 @@ module AASM
|
|
2
2
|
|
3
3
|
def self.included(base) #:nodoc:
|
4
4
|
base.extend AASM::ClassMethods
|
5
|
+
|
6
|
+
# do not overwrite existing state machines, which could have been created by
|
7
|
+
# inheritance, see class method inherited
|
5
8
|
AASM::StateMachine[base] ||= AASM::StateMachine.new('')
|
9
|
+
|
6
10
|
AASM::Persistence.load_persistence(base)
|
7
11
|
super
|
8
12
|
end
|
data/lib/aasm/base.rb
CHANGED
@@ -12,6 +12,12 @@ module AASM
|
|
12
12
|
@state_machine.config.whiny_transitions = true # this is the default, so let's cry
|
13
13
|
end
|
14
14
|
|
15
|
+
if options.key?(:create_scopes)
|
16
|
+
@state_machine.config.create_scopes = options[:create_scopes]
|
17
|
+
elsif @state_machine.config.create_scopes.nil?
|
18
|
+
@state_machine.config.create_scopes = true # this is the default, so let's create scopes
|
19
|
+
end
|
20
|
+
|
15
21
|
if options.key?(:skip_validation_on_save)
|
16
22
|
@state_machine.config.skip_validation_on_save = options[:skip_validation_on_save]
|
17
23
|
elsif @state_machine.config.skip_validation_on_save.nil?
|
data/lib/aasm/event.rb
CHANGED
@@ -64,16 +64,16 @@ module AASM
|
|
64
64
|
self
|
65
65
|
end
|
66
66
|
|
67
|
-
# Execute if test
|
67
|
+
# Execute if test == false, otherwise return true/false depending on whether it would fire
|
68
68
|
def _fire(obj, test, to_state=nil, *args)
|
69
|
+
result = test ? false : nil
|
69
70
|
if @transitions.map(&:from).any?
|
70
71
|
transitions = @transitions.select { |t| t.from == obj.aasm_current_state }
|
71
|
-
return
|
72
|
+
return result if transitions.size == 0
|
72
73
|
else
|
73
74
|
transitions = @transitions
|
74
75
|
end
|
75
76
|
|
76
|
-
result = test ? false : nil
|
77
77
|
transitions.each do |transition|
|
78
78
|
next if to_state and !Array(transition.to).include?(to_state)
|
79
79
|
if transition.perform(obj, *args)
|
@@ -87,7 +87,7 @@ module AASM
|
|
87
87
|
# make sure to create a (named) scope for each state
|
88
88
|
def state_with_scope(name, *args)
|
89
89
|
state_without_scope(name, *args)
|
90
|
-
|
90
|
+
if AASM::StateMachine[@clazz].config.create_scopes && !@clazz.respond_to?(name)
|
91
91
|
if @clazz.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base")
|
92
92
|
|
93
93
|
conditions = {"#{@clazz.table_name}.#{@clazz.aasm_column}" => name.to_s}
|
data/lib/aasm/version.rb
CHANGED
data/spec/models/persistence.rb
CHANGED
data/spec/schema.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
ActiveRecord::Schema.define(:version => 0) do
|
2
2
|
|
3
|
-
%w{gates readers writers transients simples simple_new_dsls thieves localizer_test_models persisted_states provided_and_persisted_states}.each do |table_name|
|
3
|
+
%w{gates readers writers transients simples simple_new_dsls no_scopes thieves localizer_test_models persisted_states provided_and_persisted_states}.each do |table_name|
|
4
4
|
create_table table_name, :force => true do |t|
|
5
5
|
t.string "aasm_state"
|
6
6
|
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: 3.0.
|
4
|
+
version: 3.0.20
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,22 +12,27 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|
19
|
-
requirement:
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
|
-
- - =
|
22
|
+
- - '='
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: 3.2.12
|
25
25
|
type: :development
|
26
26
|
prerelease: false
|
27
|
-
version_requirements:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - '='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.2.12
|
28
33
|
- !ruby/object:Gem::Dependency
|
29
34
|
name: mongoid
|
30
|
-
requirement:
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
31
36
|
none: false
|
32
37
|
requirements:
|
33
38
|
- - ! '>='
|
@@ -35,10 +40,15 @@ dependencies:
|
|
35
40
|
version: '0'
|
36
41
|
type: :development
|
37
42
|
prerelease: false
|
38
|
-
version_requirements:
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
39
49
|
- !ruby/object:Gem::Dependency
|
40
50
|
name: rake
|
41
|
-
requirement:
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
42
52
|
none: false
|
43
53
|
requirements:
|
44
54
|
- - ! '>='
|
@@ -46,10 +56,15 @@ dependencies:
|
|
46
56
|
version: '0'
|
47
57
|
type: :development
|
48
58
|
prerelease: false
|
49
|
-
version_requirements:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
50
65
|
- !ruby/object:Gem::Dependency
|
51
66
|
name: sdoc
|
52
|
-
requirement:
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
53
68
|
none: false
|
54
69
|
requirements:
|
55
70
|
- - ! '>='
|
@@ -57,10 +72,15 @@ dependencies:
|
|
57
72
|
version: '0'
|
58
73
|
type: :development
|
59
74
|
prerelease: false
|
60
|
-
version_requirements:
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
61
81
|
- !ruby/object:Gem::Dependency
|
62
82
|
name: rspec
|
63
|
-
requirement:
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
64
84
|
none: false
|
65
85
|
requirements:
|
66
86
|
- - ~>
|
@@ -68,10 +88,15 @@ dependencies:
|
|
68
88
|
version: '2.0'
|
69
89
|
type: :development
|
70
90
|
prerelease: false
|
71
|
-
version_requirements:
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
72
97
|
- !ruby/object:Gem::Dependency
|
73
98
|
name: rr
|
74
|
-
requirement:
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
75
100
|
none: false
|
76
101
|
requirements:
|
77
102
|
- - ! '>='
|
@@ -79,10 +104,15 @@ dependencies:
|
|
79
104
|
version: '0'
|
80
105
|
type: :development
|
81
106
|
prerelease: false
|
82
|
-
version_requirements:
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
83
113
|
- !ruby/object:Gem::Dependency
|
84
114
|
name: sqlite3
|
85
|
-
requirement:
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
86
116
|
none: false
|
87
117
|
requirements:
|
88
118
|
- - ! '>='
|
@@ -90,10 +120,15 @@ dependencies:
|
|
90
120
|
version: '0'
|
91
121
|
type: :development
|
92
122
|
prerelease: false
|
93
|
-
version_requirements:
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
94
129
|
- !ruby/object:Gem::Dependency
|
95
130
|
name: minitest
|
96
|
-
requirement:
|
131
|
+
requirement: !ruby/object:Gem::Requirement
|
97
132
|
none: false
|
98
133
|
requirements:
|
99
134
|
- - ! '>='
|
@@ -101,10 +136,15 @@ dependencies:
|
|
101
136
|
version: '0'
|
102
137
|
type: :development
|
103
138
|
prerelease: false
|
104
|
-
version_requirements:
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
105
145
|
- !ruby/object:Gem::Dependency
|
106
146
|
name: ruby-debug-completion
|
107
|
-
requirement:
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
108
148
|
none: false
|
109
149
|
requirements:
|
110
150
|
- - ! '>='
|
@@ -112,10 +152,15 @@ dependencies:
|
|
112
152
|
version: '0'
|
113
153
|
type: :development
|
114
154
|
prerelease: false
|
115
|
-
version_requirements:
|
155
|
+
version_requirements: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
116
161
|
- !ruby/object:Gem::Dependency
|
117
162
|
name: coveralls
|
118
|
-
requirement:
|
163
|
+
requirement: !ruby/object:Gem::Requirement
|
119
164
|
none: false
|
120
165
|
requirements:
|
121
166
|
- - ! '>='
|
@@ -123,7 +168,12 @@ dependencies:
|
|
123
168
|
version: '0'
|
124
169
|
type: :development
|
125
170
|
prerelease: false
|
126
|
-
version_requirements:
|
171
|
+
version_requirements: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ! '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
127
177
|
description: AASM is a continuation of the acts as state machine rails plugin, built
|
128
178
|
for plain Ruby objects.
|
129
179
|
email: scott@elitists.net, ttilley@gmail.com, aasm@mt7.de
|
@@ -171,6 +221,7 @@ files:
|
|
171
221
|
- spec/models/father.rb
|
172
222
|
- spec/models/foo.rb
|
173
223
|
- spec/models/invalid_persistor.rb
|
224
|
+
- spec/models/mongoid/no_scope_mongoid.rb
|
174
225
|
- spec/models/mongoid/simple_mongoid.rb
|
175
226
|
- spec/models/mongoid/simple_new_dsl_mongoid.rb
|
176
227
|
- spec/models/not_auto_loaded/process.rb
|
@@ -222,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
273
|
version: '0'
|
223
274
|
requirements: []
|
224
275
|
rubyforge_project:
|
225
|
-
rubygems_version: 1.8.
|
276
|
+
rubygems_version: 1.8.24
|
226
277
|
signing_key:
|
227
278
|
specification_version: 3
|
228
279
|
summary: State machine mixin for Ruby objects
|
@@ -240,6 +291,7 @@ test_files:
|
|
240
291
|
- spec/models/father.rb
|
241
292
|
- spec/models/foo.rb
|
242
293
|
- spec/models/invalid_persistor.rb
|
294
|
+
- spec/models/mongoid/no_scope_mongoid.rb
|
243
295
|
- spec/models/mongoid/simple_mongoid.rb
|
244
296
|
- spec/models/mongoid/simple_new_dsl_mongoid.rb
|
245
297
|
- spec/models/not_auto_loaded/process.rb
|