state_machine 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.travis.yml +16 -0
- data/.yardopts +5 -0
- data/Appraisals +260 -0
- data/CHANGELOG.rdoc +15 -0
- data/Gemfile +3 -0
- data/README.rdoc +156 -29
- data/Rakefile +31 -57
- data/gemfiles/active_model-3.0.0.gemfile +7 -0
- data/gemfiles/active_model-3.0.0.gemfile.lock +32 -0
- data/gemfiles/active_model-3.0.5.gemfile +7 -0
- data/gemfiles/active_model-3.0.5.gemfile.lock +32 -0
- data/gemfiles/active_record-2.0.0.gemfile +8 -0
- data/gemfiles/active_record-2.0.0.gemfile.lock +30 -0
- data/gemfiles/active_record-2.0.5.gemfile +8 -0
- data/gemfiles/active_record-2.0.5.gemfile.lock +30 -0
- data/gemfiles/active_record-2.1.0.gemfile +8 -0
- data/gemfiles/active_record-2.1.0.gemfile.lock +30 -0
- data/gemfiles/active_record-2.1.2.gemfile +8 -0
- data/gemfiles/active_record-2.1.2.gemfile.lock +30 -0
- data/gemfiles/active_record-2.2.3.gemfile +8 -0
- data/gemfiles/active_record-2.2.3.gemfile.lock +30 -0
- data/gemfiles/active_record-2.3.12.gemfile +8 -0
- data/gemfiles/active_record-2.3.12.gemfile.lock +30 -0
- data/gemfiles/active_record-3.0.0.gemfile +8 -0
- data/gemfiles/active_record-3.0.0.gemfile.lock +44 -0
- data/gemfiles/active_record-3.0.5.gemfile +8 -0
- data/gemfiles/active_record-3.0.5.gemfile.lock +43 -0
- data/gemfiles/data_mapper-0.10.2.gemfile +12 -0
- data/gemfiles/data_mapper-0.10.2.gemfile.lock +45 -0
- data/gemfiles/data_mapper-0.9.11.gemfile +12 -0
- data/gemfiles/data_mapper-0.9.11.gemfile.lock +47 -0
- data/gemfiles/data_mapper-0.9.4.gemfile +12 -0
- data/gemfiles/data_mapper-0.9.4.gemfile.lock +61 -0
- data/gemfiles/data_mapper-0.9.7.gemfile +12 -0
- data/gemfiles/data_mapper-0.9.7.gemfile.lock +57 -0
- data/gemfiles/data_mapper-1.0.0.gemfile +12 -0
- data/gemfiles/data_mapper-1.0.0.gemfile.lock +53 -0
- data/gemfiles/data_mapper-1.0.1.gemfile +12 -0
- data/gemfiles/data_mapper-1.0.1.gemfile.lock +53 -0
- data/gemfiles/data_mapper-1.0.2.gemfile +12 -0
- data/gemfiles/data_mapper-1.0.2.gemfile.lock +53 -0
- data/gemfiles/data_mapper-1.1.0.gemfile +12 -0
- data/gemfiles/data_mapper-1.1.0.gemfile.lock +51 -0
- data/gemfiles/default.gemfile +7 -0
- data/gemfiles/default.gemfile.lock +24 -0
- data/gemfiles/mongo_mapper-0.5.5.gemfile +8 -0
- data/gemfiles/mongo_mapper-0.5.5.gemfile.lock +33 -0
- data/gemfiles/mongo_mapper-0.5.8.gemfile +8 -0
- data/gemfiles/mongo_mapper-0.5.8.gemfile.lock +33 -0
- data/gemfiles/mongo_mapper-0.6.0.gemfile +8 -0
- data/gemfiles/mongo_mapper-0.6.0.gemfile.lock +33 -0
- data/gemfiles/mongo_mapper-0.6.10.gemfile +8 -0
- data/gemfiles/mongo_mapper-0.6.10.gemfile.lock +33 -0
- data/gemfiles/mongo_mapper-0.7.0.gemfile +8 -0
- data/gemfiles/mongo_mapper-0.7.0.gemfile.lock +33 -0
- data/gemfiles/mongo_mapper-0.7.5.gemfile +8 -0
- data/gemfiles/mongo_mapper-0.7.5.gemfile.lock +36 -0
- data/gemfiles/mongo_mapper-0.8.0.gemfile +10 -0
- data/gemfiles/mongo_mapper-0.8.0.gemfile.lock +40 -0
- data/gemfiles/mongo_mapper-0.8.3.gemfile +10 -0
- data/gemfiles/mongo_mapper-0.8.3.gemfile.lock +40 -0
- data/gemfiles/mongo_mapper-0.8.4.gemfile +8 -0
- data/gemfiles/mongo_mapper-0.8.4.gemfile.lock +38 -0
- data/gemfiles/mongo_mapper-0.8.6.gemfile +8 -0
- data/gemfiles/mongo_mapper-0.8.6.gemfile.lock +38 -0
- data/gemfiles/mongo_mapper-0.9.0.gemfile +7 -0
- data/gemfiles/mongo_mapper-0.9.0.gemfile.lock +41 -0
- data/gemfiles/mongoid-2.0.0.gemfile +7 -0
- data/gemfiles/mongoid-2.0.0.gemfile.lock +42 -0
- data/gemfiles/mongoid-2.1.4.gemfile +7 -0
- data/gemfiles/mongoid-2.1.4.gemfile.lock +40 -0
- data/gemfiles/sequel-2.11.0.gemfile +8 -0
- data/gemfiles/sequel-2.11.0.gemfile.lock +28 -0
- data/gemfiles/sequel-2.12.0.gemfile +8 -0
- data/gemfiles/sequel-2.12.0.gemfile.lock +28 -0
- data/gemfiles/sequel-2.8.0.gemfile +8 -0
- data/gemfiles/sequel-2.8.0.gemfile.lock +28 -0
- data/gemfiles/sequel-3.0.0.gemfile +8 -0
- data/gemfiles/sequel-3.0.0.gemfile.lock +28 -0
- data/gemfiles/sequel-3.13.0.gemfile +8 -0
- data/gemfiles/sequel-3.13.0.gemfile.lock +28 -0
- data/gemfiles/sequel-3.14.0.gemfile +8 -0
- data/gemfiles/sequel-3.14.0.gemfile.lock +28 -0
- data/gemfiles/sequel-3.23.0.gemfile +8 -0
- data/gemfiles/sequel-3.23.0.gemfile.lock +28 -0
- data/gemfiles/sequel-3.24.0.gemfile +8 -0
- data/gemfiles/sequel-3.24.0.gemfile.lock +28 -0
- data/lib/state_machine/event.rb +13 -90
- data/lib/state_machine/helper_module.rb +17 -0
- data/lib/state_machine/integrations/active_model.rb +35 -0
- data/lib/state_machine/integrations/active_record.rb +41 -2
- data/lib/state_machine/integrations/data_mapper.rb +17 -2
- data/lib/state_machine/integrations/mongo_mapper.rb +34 -7
- data/lib/state_machine/integrations/mongoid.rb +34 -26
- data/lib/state_machine/integrations/mongoid/versions.rb +29 -3
- data/lib/state_machine/integrations/sequel.rb +22 -72
- data/lib/state_machine/integrations/sequel/versions.rb +87 -6
- data/lib/state_machine/machine.rb +279 -19
- data/lib/state_machine/state.rb +2 -2
- data/lib/state_machine/state_context.rb +133 -0
- data/lib/state_machine/version.rb +3 -0
- data/state_machine.gemspec +22 -0
- data/test/test_helper.rb +1 -3
- data/test/unit/branch_test.rb +1 -3
- data/test/unit/event_collection_test.rb +3 -3
- data/test/unit/event_test.rb +1 -3
- data/test/unit/helper_module_test.rb +17 -0
- data/test/unit/integrations/active_model_test.rb +0 -4
- data/test/unit/integrations/active_record_test.rb +50 -9
- data/test/unit/integrations/data_mapper_test.rb +267 -253
- data/test/unit/integrations/mongo_mapper_test.rb +47 -15
- data/test/unit/integrations/mongoid_test.rb +50 -8
- data/test/unit/integrations/sequel_test.rb +10 -6
- data/test/unit/machine_test.rb +206 -25
- data/test/unit/state_context_test.rb +421 -0
- data/test/unit/state_test.rb +20 -3
- metadata +303 -128
- data/lib/state_machine/condition_proxy.rb +0 -94
- data/test/unit/condition_proxy_test.rb +0 -328
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
|
3
|
+
specs:
|
4
|
+
state_machine (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://www.rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (0.3.8)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.10)
|
14
|
+
ruby-graphviz (1.0.0)
|
15
|
+
sequel (2.12.0)
|
16
|
+
sqlite3-ruby (1.3.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
appraisal (~> 0.3.8)
|
23
|
+
rake
|
24
|
+
rcov
|
25
|
+
ruby-graphviz (~> 1.0)
|
26
|
+
sequel (= 2.12.0)
|
27
|
+
sqlite3-ruby (= 1.3.1)
|
28
|
+
state_machine!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
|
3
|
+
specs:
|
4
|
+
state_machine (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://www.rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (0.3.8)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.10)
|
14
|
+
ruby-graphviz (1.0.0)
|
15
|
+
sequel (2.8.0)
|
16
|
+
sqlite3-ruby (1.3.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
appraisal (~> 0.3.8)
|
23
|
+
rake
|
24
|
+
rcov
|
25
|
+
ruby-graphviz (~> 1.0)
|
26
|
+
sequel (= 2.8.0)
|
27
|
+
sqlite3-ruby (= 1.3.1)
|
28
|
+
state_machine!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
|
3
|
+
specs:
|
4
|
+
state_machine (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://www.rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (0.3.8)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.10)
|
14
|
+
ruby-graphviz (1.0.0)
|
15
|
+
sequel (3.0.0)
|
16
|
+
sqlite3-ruby (1.3.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
appraisal (~> 0.3.8)
|
23
|
+
rake
|
24
|
+
rcov
|
25
|
+
ruby-graphviz (~> 1.0)
|
26
|
+
sequel (= 3.0.0)
|
27
|
+
sqlite3-ruby (= 1.3.1)
|
28
|
+
state_machine!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
|
3
|
+
specs:
|
4
|
+
state_machine (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://www.rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (0.3.8)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.10)
|
14
|
+
ruby-graphviz (1.0.0)
|
15
|
+
sequel (3.13.0)
|
16
|
+
sqlite3-ruby (1.3.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
appraisal (~> 0.3.8)
|
23
|
+
rake
|
24
|
+
rcov
|
25
|
+
ruby-graphviz (~> 1.0)
|
26
|
+
sequel (= 3.13.0)
|
27
|
+
sqlite3-ruby (= 1.3.1)
|
28
|
+
state_machine!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
|
3
|
+
specs:
|
4
|
+
state_machine (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://www.rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (0.3.8)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.10)
|
14
|
+
ruby-graphviz (1.0.0)
|
15
|
+
sequel (3.14.0)
|
16
|
+
sqlite3-ruby (1.3.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
appraisal (~> 0.3.8)
|
23
|
+
rake
|
24
|
+
rcov
|
25
|
+
ruby-graphviz (~> 1.0)
|
26
|
+
sequel (= 3.14.0)
|
27
|
+
sqlite3-ruby (= 1.3.1)
|
28
|
+
state_machine!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
|
3
|
+
specs:
|
4
|
+
state_machine (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://www.rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (0.3.8)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.10)
|
14
|
+
ruby-graphviz (1.0.0)
|
15
|
+
sequel (3.23.0)
|
16
|
+
sqlite3-ruby (1.3.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
appraisal (~> 0.3.8)
|
23
|
+
rake
|
24
|
+
rcov
|
25
|
+
ruby-graphviz (~> 1.0)
|
26
|
+
sequel (= 3.23.0)
|
27
|
+
sqlite3-ruby (= 1.3.1)
|
28
|
+
state_machine!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
|
3
|
+
specs:
|
4
|
+
state_machine (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://www.rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (0.3.8)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.10)
|
14
|
+
ruby-graphviz (1.0.0)
|
15
|
+
sequel (3.24.0)
|
16
|
+
sqlite3-ruby (1.3.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
appraisal (~> 0.3.8)
|
23
|
+
rake
|
24
|
+
rcov
|
25
|
+
ruby-graphviz (~> 1.0)
|
26
|
+
sequel (= 3.24.0)
|
27
|
+
sqlite3-ruby (= 1.3.1)
|
28
|
+
state_machine!
|
data/lib/state_machine/event.rb
CHANGED
@@ -84,96 +84,19 @@ module StateMachine
|
|
84
84
|
# Creates a new transition that determines what to change the current state
|
85
85
|
# to when this event fires.
|
86
86
|
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
# for
|
100
|
-
# * <tt>all</tt> - Matches every state in the machine
|
101
|
-
# * <tt>all - [:parked, :idling, ...]</tt> - Matches every state except those specified
|
102
|
-
# * <tt>any</tt> - An alias for +all+ (matches every state in the machine)
|
103
|
-
# * <tt>same</tt> - Matches the same state being transitioned from
|
104
|
-
#
|
105
|
-
# See StateMachine::MatcherHelpers for more information.
|
106
|
-
#
|
107
|
-
# Examples:
|
108
|
-
#
|
109
|
-
# transition all => nil # Transitions to nil regardless of the current state
|
110
|
-
# transition all => :idling # Transitions to :idling regardless of the current state
|
111
|
-
# transition all - [:idling, :first_gear] => :idling # Transitions every state but :idling and :first_gear to :idling
|
112
|
-
# transition nil => :idling # Transitions to :idling from the nil state
|
113
|
-
# transition :parked => :idling # Transitions to :idling if :parked
|
114
|
-
# transition [:parked, :stalled] => :idling # Transitions to :idling if :parked or :stalled
|
115
|
-
#
|
116
|
-
# transition :parked => same # Loops :parked back to :parked
|
117
|
-
# transition [:parked, :stalled] => same # Loops either :parked or :stalled back to the same state
|
118
|
-
# transition all - :parked => same # Loops every state but :parked back to the same state
|
119
|
-
#
|
120
|
-
# # Transitions to :idling if :parked, :first_gear if :idling, or :second_gear if :first_gear
|
121
|
-
# transition :parked => :idling, :idling => :first_gear, :first_gear => :second_gear
|
122
|
-
#
|
123
|
-
# == Verbose transitions
|
124
|
-
#
|
125
|
-
# Transitions can also be defined use an explicit set of deprecated
|
126
|
-
# configuration options:
|
127
|
-
# * <tt>:from</tt> - A state or array of states that can be transitioned from.
|
128
|
-
# If not specified, then the transition can occur for *any* state.
|
129
|
-
# * <tt>:to</tt> - The state that's being transitioned to. If not specified,
|
130
|
-
# then the transition will simply loop back (i.e. the state will not change).
|
131
|
-
# * <tt>:except_from</tt> - A state or array of states that *cannot* be
|
132
|
-
# transitioned from.
|
133
|
-
#
|
134
|
-
# Examples:
|
135
|
-
#
|
136
|
-
# transition :to => nil
|
137
|
-
# transition :to => :idling
|
138
|
-
# transition :except_from => [:idling, :first_gear], :to => :idling
|
139
|
-
# transition :from => nil, :to => :idling
|
140
|
-
# transition :from => [:parked, :stalled], :to => :idling
|
141
|
-
#
|
142
|
-
# transition :from => :parked
|
143
|
-
# transition :from => [:parked, :stalled]
|
144
|
-
# transition :except_from => :parked
|
145
|
-
#
|
146
|
-
# Notice that the above examples are the verbose equivalent of the examples
|
147
|
-
# described initially.
|
148
|
-
#
|
149
|
-
# == Conditions
|
150
|
-
#
|
151
|
-
# In addition to the state requirements for each transition, a condition
|
152
|
-
# can also be defined to help determine whether that transition is
|
153
|
-
# available. These options will work on both the normal and verbose syntax.
|
154
|
-
#
|
155
|
-
# Configuration options:
|
156
|
-
# * <tt>:if</tt> - A method, proc or string to call to determine if the
|
157
|
-
# transition should occur (e.g. :if => :moving?, or :if => lambda {|vehicle| vehicle.speed > 60}).
|
158
|
-
# The condition should return or evaluate to true or false.
|
159
|
-
# * <tt>:unless</tt> - A method, proc or string to call to determine if the
|
160
|
-
# transition should not occur (e.g. :unless => :stopped?, or :unless => lambda {|vehicle| vehicle.speed <= 60}).
|
161
|
-
# The condition should return or evaluate to true or false.
|
162
|
-
#
|
163
|
-
# Examples:
|
164
|
-
#
|
165
|
-
# transition :parked => :idling, :if => :moving?
|
166
|
-
# transition :parked => :idling, :unless => :stopped?
|
167
|
-
# transition :idling => :first_gear, :first_gear => :second_gear, :if => :seatbelt_on?
|
168
|
-
#
|
169
|
-
# transition :from => :parked, :to => :idling, :if => :moving?
|
170
|
-
# transition :from => :parked, :to => :idling, :unless => :stopped?
|
171
|
-
#
|
172
|
-
# == Order of operations
|
173
|
-
#
|
174
|
-
# Transitions are evaluated in the order in which they're defined. As a
|
175
|
-
# result, if more than one transition applies to a given object, then the
|
176
|
-
# first transition that matches will be performed.
|
87
|
+
# Since this transition is being defined within an event context, you do
|
88
|
+
# *not* need to specify the <tt>:on</tt> option for the transition. For
|
89
|
+
# example:
|
90
|
+
#
|
91
|
+
# state_machine do
|
92
|
+
# event :ignite do
|
93
|
+
# transition :parked => :idling, :idling => same, :if => :seatbelt_on? # Transitions to :idling if seatbelt is on
|
94
|
+
# transition all => :parked, :unless => :seatbelt_on? # Transitions to :parked if seatbelt is off
|
95
|
+
# end
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# See StateMachine::Machine#transition for a description of the possible
|
99
|
+
# configurations for defining transitions.
|
177
100
|
def transition(options)
|
178
101
|
raise ArgumentError, 'Must specify as least one transition requirement' if options.empty?
|
179
102
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module StateMachine
|
2
|
+
# Represents a type of module that defines instance / class methods for a
|
3
|
+
# state machine
|
4
|
+
class HelperModule < Module #:nodoc:
|
5
|
+
def initialize(machine, kind)
|
6
|
+
@machine = machine
|
7
|
+
@kind = kind
|
8
|
+
end
|
9
|
+
|
10
|
+
# Provides a human-readable description of the module
|
11
|
+
def to_s
|
12
|
+
owner_class = @machine.owner_class
|
13
|
+
owner_class_name = owner_class.name && !owner_class.name.empty? ? owner_class.name : owner_class.to_s
|
14
|
+
"#{owner_class_name} #{@machine.name.inspect} #{@kind} helpers"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -51,6 +51,40 @@ module StateMachine
|
|
51
51
|
# end
|
52
52
|
# end
|
53
53
|
#
|
54
|
+
# == Validations
|
55
|
+
#
|
56
|
+
# As mentioned in StateMachine::Machine#state, you can define behaviors,
|
57
|
+
# like validations, that only execute for certain states. One *important*
|
58
|
+
# caveat here is that, due to a constraint in ActiveModel's validation
|
59
|
+
# framework, custom validators will not work as expected when defined to run
|
60
|
+
# in multiple states. For example:
|
61
|
+
#
|
62
|
+
# class Vehicle
|
63
|
+
# include ActiveModel::Validations
|
64
|
+
#
|
65
|
+
# state_machine do
|
66
|
+
# ...
|
67
|
+
# state :first_gear, :second_gear do
|
68
|
+
# validate :speed_is_legal
|
69
|
+
# end
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# In this case, the <tt>:speed_is_legal</tt> validation will only get run
|
74
|
+
# for the <tt>:second_gear</tt> state. To avoid this, you can define your
|
75
|
+
# custom validation like so:
|
76
|
+
#
|
77
|
+
# class Vehicle
|
78
|
+
# include ActiveModel::Validations
|
79
|
+
#
|
80
|
+
# state_machine do
|
81
|
+
# ...
|
82
|
+
# state :first_gear, :second_gear do
|
83
|
+
# validate {|vehicle| vehicle.speed_is_legal}
|
84
|
+
# end
|
85
|
+
# end
|
86
|
+
# end
|
87
|
+
#
|
54
88
|
# == Validation errors
|
55
89
|
#
|
56
90
|
# In order to hook in validation support for your model, the
|
@@ -380,6 +414,7 @@ module StateMachine
|
|
380
414
|
|
381
415
|
# Initializes class-level extensions and defaults for this machine
|
382
416
|
def after_initialize
|
417
|
+
super
|
383
418
|
load_locale
|
384
419
|
load_observer_extensions
|
385
420
|
add_default_callbacks
|