aasm 3.0.8 → 3.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/aasm.gemspec +2 -2
- data/lib/aasm/state_machine.rb +6 -7
- data/lib/aasm/supporting_classes/event.rb +3 -3
- data/lib/aasm/version.rb +1 -1
- data/spec/spec_helpers/models_spec_helper.rb +10 -1
- data/spec/unit/auth_machine_spec.rb +17 -0
- metadata +24 -23
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# AASM - Ruby state machines
|
1
|
+
# AASM - Ruby state machines [![Build Status](https://secure.travis-ci.org/aasm/aasm.png)](http://travis-ci.org/aasm/aasm)
|
2
2
|
|
3
3
|
This package contains AASM, a library for adding finite state machines to Ruby classes.
|
4
4
|
|
@@ -160,7 +160,7 @@ This model can change AASM states which are stored into the database, even if th
|
|
160
160
|
|
161
161
|
## Changelog ##
|
162
162
|
|
163
|
-
Look at the [CHANGELOG](https://github.com/
|
163
|
+
Look at the [CHANGELOG](https://github.com/aasm/aasm/blob/master/CHANGELOG.md) for details.
|
164
164
|
|
165
165
|
|
166
166
|
## Authors ##
|
data/aasm.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "aasm"
|
7
7
|
s.version = AASM::VERSION
|
8
8
|
s.authors = ["Scott Barron", "Scott Petersen", "Travis Tilley", "Thorsten Boettger"]
|
9
|
-
s.email = %q{scott@elitists.net, ttilley@gmail.com}
|
10
|
-
s.homepage = %q{
|
9
|
+
s.email = %q{scott@elitists.net, ttilley@gmail.com, aasm@mt7.de}
|
10
|
+
s.homepage = %q{https://github.com/aasm/aasm}
|
11
11
|
s.summary = %q{State machine mixin for Ruby objects}
|
12
12
|
s.description = %q{AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.}
|
13
13
|
s.date = Time.now
|
data/lib/aasm/state_machine.rb
CHANGED
@@ -3,11 +3,11 @@ module AASM
|
|
3
3
|
def self.[](clazz)
|
4
4
|
(@machines ||= {})[clazz.to_s]
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def self.[]=(clazz, machine)
|
8
8
|
(@machines ||= {})[clazz.to_s] = machine
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
attr_accessor :states, :events, :initial_state, :config
|
12
12
|
attr_reader :name
|
13
13
|
|
@@ -19,11 +19,10 @@ module AASM
|
|
19
19
|
@config = OpenStruct.new
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
klone
|
22
|
+
def initialize_copy(orig)
|
23
|
+
super
|
24
|
+
@states = @states.dup
|
25
|
+
@events = @events.dup
|
27
26
|
end
|
28
27
|
|
29
28
|
def create_state(name, options)
|
@@ -12,14 +12,14 @@ module AASM
|
|
12
12
|
# a neutered version of fire - it doesn't actually fire the event, it just
|
13
13
|
# executes the transition guards to determine if a transition is even
|
14
14
|
# an option given current conditions.
|
15
|
-
def may_fire?(obj, to_state=nil)
|
15
|
+
def may_fire?(obj, to_state=nil, *args)
|
16
16
|
transitions = @transitions.select { |t| t.from == obj.aasm_current_state }
|
17
17
|
return false if transitions.size == 0
|
18
|
-
|
18
|
+
|
19
19
|
result = false
|
20
20
|
transitions.each do |transition|
|
21
21
|
next if to_state and !Array(transition.to).include?(to_state)
|
22
|
-
if transition.perform(obj)
|
22
|
+
if transition.perform(obj, *args)
|
23
23
|
result = true
|
24
24
|
break
|
25
25
|
end
|
data/lib/aasm/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Dir[File.dirname(__FILE__) + "/../models/*.rb"].each { |f| require File.expand_path(f) }
|
1
|
+
Dir[File.dirname(__FILE__) + "/../models/*.rb"].sort.each { |f| require File.expand_path(f) }
|
2
2
|
|
3
3
|
class Foo
|
4
4
|
include AASM
|
@@ -87,6 +87,7 @@ class AuthMachine
|
|
87
87
|
state :active, :enter => :do_activate
|
88
88
|
state :suspended
|
89
89
|
state :deleted, :enter => :do_delete, :exit => :do_undelete
|
90
|
+
state :waiting
|
90
91
|
|
91
92
|
event :register do
|
92
93
|
transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| u.can_register? }
|
@@ -114,6 +115,10 @@ class AuthMachine
|
|
114
115
|
transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| u.has_activation_code? }
|
115
116
|
transitions :from => :suspended, :to => :passive
|
116
117
|
end
|
118
|
+
|
119
|
+
event :wait do
|
120
|
+
transitions :from => :suspended, :to => :waiting, :guard => :if_polite?
|
121
|
+
end
|
117
122
|
end
|
118
123
|
|
119
124
|
def initialize
|
@@ -150,6 +155,10 @@ class AuthMachine
|
|
150
155
|
def has_activation_code?
|
151
156
|
!!@activation_code
|
152
157
|
end
|
158
|
+
|
159
|
+
def if_polite?(phrase = nil)
|
160
|
+
phrase == :please
|
161
|
+
end
|
153
162
|
end
|
154
163
|
|
155
164
|
class ThisNameBetterNotBeInUse
|
@@ -28,6 +28,22 @@ describe 'AuthMachine when being unsuspended' do
|
|
28
28
|
@auth.suspend!
|
29
29
|
@auth.may_unsuspend?(:active).should_not be_true
|
30
30
|
end
|
31
|
+
|
32
|
+
it 'should be able to be unsuspended into active if polite' do
|
33
|
+
@auth = AuthMachine.new
|
34
|
+
@auth.suspend!
|
35
|
+
@auth.may_wait?(:waiting, :please).should be_true
|
36
|
+
@auth.wait!(nil, :please)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should not be able to be unsuspended into active if not polite' do
|
40
|
+
@auth = AuthMachine.new
|
41
|
+
@auth.suspend!
|
42
|
+
@auth.may_wait?(:waiting).should_not be_true
|
43
|
+
@auth.may_wait?(:waiting, :rude).should_not be_true
|
44
|
+
lambda {@auth.wait!(nil, :rude)}.should raise_error(AASM::InvalidTransition)
|
45
|
+
lambda {@auth.wait!}.should raise_error(AASM::InvalidTransition)
|
46
|
+
end
|
31
47
|
|
32
48
|
it 'should not be able to be unpassified' do
|
33
49
|
@auth = AuthMachine.new
|
@@ -36,6 +52,7 @@ describe 'AuthMachine when being unsuspended' do
|
|
36
52
|
@auth.unsuspend!
|
37
53
|
|
38
54
|
@auth.may_unpassify?.should_not be_true
|
55
|
+
lambda {@auth.unpassify!}.should raise_error(AASM::InvalidTransition)
|
39
56
|
end
|
40
57
|
|
41
58
|
it 'should be active if previously activated' do
|
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.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,11 +12,11 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2012-
|
15
|
+
date: 2012-09-26 00:00:00.000000000Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|
19
|
-
requirement: &
|
19
|
+
requirement: &70261337622160 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
22
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: '0'
|
25
25
|
type: :development
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *70261337622160
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
|
-
requirement: &
|
30
|
+
requirement: &70261337621740 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
version: '0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *70261337621740
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: sdoc
|
41
|
-
requirement: &
|
41
|
+
requirement: &70261337621320 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
44
|
- - ! '>='
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
version: '0'
|
47
47
|
type: :development
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *70261337621320
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: rspec
|
52
|
-
requirement: &
|
52
|
+
requirement: &70261337620820 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ~>
|
@@ -57,10 +57,10 @@ dependencies:
|
|
57
57
|
version: '2.0'
|
58
58
|
type: :development
|
59
59
|
prerelease: false
|
60
|
-
version_requirements: *
|
60
|
+
version_requirements: *70261337620820
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rr
|
63
|
-
requirement: &
|
63
|
+
requirement: &70261337620400 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
66
|
- - ! '>='
|
@@ -68,10 +68,10 @@ dependencies:
|
|
68
68
|
version: '0'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
|
-
version_requirements: *
|
71
|
+
version_requirements: *70261337620400
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: shoulda
|
74
|
-
requirement: &
|
74
|
+
requirement: &70261337651400 !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
77
77
|
- - ! '>='
|
@@ -79,10 +79,10 @@ dependencies:
|
|
79
79
|
version: '0'
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
|
-
version_requirements: *
|
82
|
+
version_requirements: *70261337651400
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
|
-
requirement: &
|
85
|
+
requirement: &70261337650980 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - ! '>='
|
@@ -90,10 +90,10 @@ dependencies:
|
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
|
-
version_requirements: *
|
93
|
+
version_requirements: *70261337650980
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: minitest
|
96
|
-
requirement: &
|
96
|
+
requirement: &70261337650560 !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
@@ -101,10 +101,10 @@ dependencies:
|
|
101
101
|
version: '0'
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
|
-
version_requirements: *
|
104
|
+
version_requirements: *70261337650560
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: ruby-debug-completion
|
107
|
-
requirement: &
|
107
|
+
requirement: &70261337650140 !ruby/object:Gem::Requirement
|
108
108
|
none: false
|
109
109
|
requirements:
|
110
110
|
- - ! '>='
|
@@ -112,16 +112,17 @@ dependencies:
|
|
112
112
|
version: '0'
|
113
113
|
type: :development
|
114
114
|
prerelease: false
|
115
|
-
version_requirements: *
|
115
|
+
version_requirements: *70261337650140
|
116
116
|
description: AASM is a continuation of the acts as state machine rails plugin, built
|
117
117
|
for plain Ruby objects.
|
118
|
-
email: scott@elitists.net, ttilley@gmail.com
|
118
|
+
email: scott@elitists.net, ttilley@gmail.com, aasm@mt7.de
|
119
119
|
executables: []
|
120
120
|
extensions: []
|
121
121
|
extra_rdoc_files: []
|
122
122
|
files:
|
123
123
|
- .document
|
124
124
|
- .gitignore
|
125
|
+
- .travis.yml
|
125
126
|
- CHANGELOG.md
|
126
127
|
- Gemfile
|
127
128
|
- LICENSE
|
@@ -166,7 +167,7 @@ files:
|
|
166
167
|
- spec/unit/new_dsl_spec.rb
|
167
168
|
- spec/unit/state_spec.rb
|
168
169
|
- spec/unit/state_transition_spec.rb
|
169
|
-
homepage:
|
170
|
+
homepage: https://github.com/aasm/aasm
|
170
171
|
licenses:
|
171
172
|
- MIT
|
172
173
|
post_install_message:
|
@@ -187,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
188
|
version: '0'
|
188
189
|
requirements: []
|
189
190
|
rubyforge_project:
|
190
|
-
rubygems_version: 1.8.
|
191
|
+
rubygems_version: 1.8.15
|
191
192
|
signing_key:
|
192
193
|
specification_version: 3
|
193
194
|
summary: State machine mixin for Ruby objects
|