pluginaweek / state_machine

Adds support for creating state machines for attributes on any Ruby class

This URL has Read+Write access

state_machine / README.rdoc
f3565041 » obrie 2008-05-04 Completely rewritten from s... 1 == state_machine
03ead942 » obrie 2006-10-21 Initial import. 2
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 3 +state_machine+ adds support for creating state machines for attributes on any
4 Ruby class.
03ead942 » obrie 2006-10-21 Initial import. 5
29c1d69f » obrie 2007-01-01 Removed install.rb files. 6 == Resources
7
1c257492 » obrie 2007-09-26 Update README format 8 API
29c1d69f » obrie 2007-01-01 Removed install.rb files. 9
f3565041 » obrie 2008-05-04 Completely rewritten from s... 10 * http://api.pluginaweek.org/state_machine
29c1d69f » obrie 2007-01-01 Removed install.rb files. 11
695fcf70 » obrie 2008-06-25 Update list of plugin resou... 12 Bugs
13
14 * http://pluginaweek.lighthouseapp.com/projects/13288-state_machine
15
29c1d69f » obrie 2007-01-01 Removed install.rb files. 16 Development
17
695fcf70 » obrie 2008-06-25 Update list of plugin resou... 18 * http://github.com/pluginaweek/state_machine
29c1d69f » obrie 2007-01-01 Removed install.rb files. 19
1c257492 » obrie 2007-09-26 Update README format 20 Source
21
695fcf70 » obrie 2008-06-25 Update list of plugin resou... 22 * git://github.com/pluginaweek/state_machine.git
1c257492 » obrie 2007-09-26 Update README format 23
29c1d69f » obrie 2007-01-01 Removed install.rb files. 24 == Description
25
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 26 State machines make it dead-simple to manage the behavior of a class. Too often,
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 27 the state of an object is kept by creating multiple boolean attributes and
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 28 deciding how to behave based on the values. This can become cumbersome and
29 difficult to maintain when the complexity of your class starts to increase.
29c1d69f » obrie 2007-01-01 Removed install.rb files. 30
179ce54f » obrie 2008-07-05 Add more descriptive except... 31 +state_machine+ simplifies this design by introducing the various parts of a real
b68d4bda » obrie 2008-12-14 Add Sequel support 32 state machine, including states, events, transitions, and callbacks. However,
33 the api is designed to be so simple you don't even need to know what a
34 state machine is :)
35
36 Some brief, high-level features include:
37 * Defining state machines on any Ruby class
38 * Multiple state machines on a single class
cfa7757d » obrie 2008-12-17 Add :namespace option for g... 39 * Namespaced state machines
b68d4bda » obrie 2008-12-14 Add Sequel support 40 * before/after transition hooks with explicit transition requirements
41 * ActiveRecord integration
42 * DataMapper integration
43 * Sequel integration
48d83dfb » obrie 2008-12-14 Add generic attribute predi... Comment 44 * State predicates
9508a446 » obrie 2009-03-03 Add support state-driven cl... 45 * State-driven instance / class behavior
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 46 * State values of any data type
47 * Dynamically-generated state values
17b472ca » obrie 2009-03-21 Add #fire_events / #fire_ev... 48 * Event parallelization
2122d327 » obrie 2009-04-03 Add #{attribute}_event for ... 49 * Attribute-based event transitions
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 50 * Inheritance
d0c99916 » obrie 2009-03-07 Add i18n support for Active... 51 * Internationalization
b68d4bda » obrie 2008-12-14 Add Sequel support 52 * GraphViz visualization creator
53
54 Examples of the usage patterns for some of the above features are shown below.
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 55 You can find much more detailed documentation in the actual API.
8563ca6b » obrie 2007-09-21 More documentation 56
57 == Usage
29c1d69f » obrie 2007-01-01 Removed install.rb files. 58
f3565041 » obrie 2008-05-04 Completely rewritten from s... 59 === Example
60
d71fedbe » obrie 2008-12-18 Simplify initialize hooks, ... 61 Below is an example of many of the features offered by this plugin, including:
179ce54f » obrie 2008-07-05 Add more descriptive except... 62 * Initial states
db88b6fa » obrie 2008-12-19 Add support for state-drive... 63 * Namespaced states
6a94afcc » obrie 2008-09-06 MAJOR REWRITE! Replace all ... Comment 64 * Transition callbacks
179ce54f » obrie 2008-07-05 Add more descriptive except... 65 * Conditional transitions
9508a446 » obrie 2009-03-03 Add support state-driven cl... 66 * State-driven instance behavior
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 67 * Customized state values
17b472ca » obrie 2009-03-21 Add #fire_events / #fire_ev... 68 * Parallel events
179ce54f » obrie 2008-07-05 Add more descriptive except... 69
d71fedbe » obrie 2008-12-18 Simplify initialize hooks, ... 70 Class definition:
71
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 72 class Vehicle
73 attr_accessor :seatbelt_on
74
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 75 state_machine :state, :initial => :parked do
7f7037e4 » obrie 2009-03-08 Tweak callback examples 76 before_transition :parked => any - :parked, :do => :put_on_seatbelt
77
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 78 after_transition :on => :crash, :do => :tow
79 after_transition :on => :repair, :do => :fix
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 80 after_transition any => :parked do |vehicle, transition|
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 81 vehicle.seatbelt_on = false
82 end
f3565041 » obrie 2008-05-04 Completely rewritten from s... 83
84 event :park do
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 85 transition [:idling, :first_gear] => :parked
f3565041 » obrie 2008-05-04 Completely rewritten from s... 86 end
87
88 event :ignite do
7f7037e4 » obrie 2009-03-08 Tweak callback examples 89 transition :stalled => same, :parked => :idling
f3565041 » obrie 2008-05-04 Completely rewritten from s... 90 end
91
92 event :idle do
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 93 transition :first_gear => :idling
f3565041 » obrie 2008-05-04 Completely rewritten from s... 94 end
95
96 event :shift_up do
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 97 transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
f3565041 » obrie 2008-05-04 Completely rewritten from s... 98 end
99
100 event :shift_down do
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 101 transition :third_gear => :second_gear, :second_gear => :first_gear
f3565041 » obrie 2008-05-04 Completely rewritten from s... 102 end
103
6a94afcc » obrie 2008-09-06 MAJOR REWRITE! Replace all ... Comment 104 event :crash do
7f7037e4 » obrie 2009-03-08 Tweak callback examples 105 transition all - [:parked, :stalled] => :stalled, :unless => :auto_shop_busy?
f3565041 » obrie 2008-05-04 Completely rewritten from s... 106 end
107
6a94afcc » obrie 2008-09-06 MAJOR REWRITE! Replace all ... Comment 108 event :repair do
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 109 transition :stalled => :parked, :if => :auto_shop_busy?
f3565041 » obrie 2008-05-04 Completely rewritten from s... 110 end
db88b6fa » obrie 2008-12-19 Add support for state-drive... 111
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 112 state :parked do
db88b6fa » obrie 2008-12-19 Add support for state-drive... 113 def speed
114 0
115 end
116 end
117
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 118 state :idling, :first_gear do
db88b6fa » obrie 2008-12-19 Add support for state-drive... 119 def speed
120 10
121 end
122 end
123
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 124 state :second_gear do
db88b6fa » obrie 2008-12-19 Add support for state-drive... 125 def speed
126 20
127 end
128 end
f3565041 » obrie 2008-05-04 Completely rewritten from s... 129 end
179ce54f » obrie 2008-07-05 Add more descriptive except... 130
09a2e3cd » obrie 2009-03-21 Move methods related to mul... 131 state_machine :alarm_state, :initial => :active, :namespace => 'alarm' do
132 event :enable do
133 transition all => :active
cfa7757d » obrie 2008-12-17 Add :namespace option for g... 134 end
135
09a2e3cd » obrie 2009-03-21 Move methods related to mul... 136 event :disable do
137 transition all => :off
cfa7757d » obrie 2008-12-17 Add :namespace option for g... 138 end
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 139
09a2e3cd » obrie 2009-03-21 Move methods related to mul... 140 state :active, :value => 1
141 state :off, :value => 0
cfa7757d » obrie 2008-12-17 Add :namespace option for g... 142 end
143
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 144 def initialize
145 @seatbelt_on = false
d71fedbe » obrie 2008-12-18 Simplify initialize hooks, ... 146 super() # NOTE: This *must* be called, otherwise states won't get initialized
179ce54f » obrie 2008-07-05 Add more descriptive except... 147 end
148
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 149 def put_on_seatbelt
150 @seatbelt_on = true
179ce54f » obrie 2008-07-05 Add more descriptive except... 151 end
152
153 def auto_shop_busy?
154 false
155 end
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 156
157 def tow
158 # tow the vehicle
159 end
160
161 def fix
162 # get the vehicle fixed by a mechanic
163 end
f3565041 » obrie 2008-05-04 Completely rewritten from s... 164 end
b5066674 » obrie 2007-09-21 Move test fixtures out of t... 165
2623e4d3 » obrie 2009-04-05 Tweak README docs 166 *Note* the comment made on the +initialize+ method in the class. In order for
167 state machine attributes to be properly initialized, <tt>super()</tt> must be called.
168 See StateMachine::MacroMethods for more information about this.
169
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 170 Using the above class as an example, you can interact with the state machine
179ce54f » obrie 2008-07-05 Add more descriptive except... 171 like so:
172
b68d4bda » obrie 2008-12-14 Add Sequel support 173 vehicle = Vehicle.new # => #<Vehicle:0xb7cf4eac @state="parked", @seatbelt_on=false>
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 174 vehicle.state # => "parked"
175 vehicle.state_name # => :parked
48d83dfb » obrie 2008-12-14 Add generic attribute predi... Comment 176 vehicle.parked? # => true
b68d4bda » obrie 2008-12-14 Add Sequel support 177 vehicle.can_ignite? # => true
26e1b8f6 » obrie 2009-03-19 Rename next_#{event}_transi... 178 vehicle.ignite_transition # => #<StateMachine::Transition attribute=:state event=:ignite from="parked" from_name=:parked to="idling" to_name=:idling>
5c2b36c4 » obrie 2009-03-19 Add #{attribute}_events / #... 179 vehicle.state_events # => [:ignite]
180 vehicle.state_transitions # => [#<StateMachine::Transition attribute=:state event=:ignite from="parked" from_name=:parked to="idling" to_name=:idling>]
37fc8a67 » obrie 2008-12-19 Fix example in README 181 vehicle.speed # => 0
182
b68d4bda » obrie 2008-12-14 Add Sequel support 183 vehicle.ignite # => true
48d83dfb » obrie 2008-12-14 Add generic attribute predi... Comment 184 vehicle.parked? # => false
185 vehicle.idling? # => true
37fc8a67 » obrie 2008-12-19 Fix example in README 186 vehicle.speed # => 10
b68d4bda » obrie 2008-12-14 Add Sequel support 187 vehicle # => #<Vehicle:0xb7cf4eac @state="idling", @seatbelt_on=true>
37fc8a67 » obrie 2008-12-19 Fix example in README 188
b68d4bda » obrie 2008-12-14 Add Sequel support 189 vehicle.shift_up # => true
db88b6fa » obrie 2008-12-19 Add support for state-drive... 190 vehicle.speed # => 10
37fc8a67 » obrie 2008-12-19 Fix example in README 191 vehicle # => #<Vehicle:0xb7cf4eac @state="first_gear", @seatbelt_on=true>
192
b68d4bda » obrie 2008-12-14 Add Sequel support 193 vehicle.shift_up # => true
db88b6fa » obrie 2008-12-19 Add support for state-drive... 194 vehicle.speed # => 20
37fc8a67 » obrie 2008-12-19 Fix example in README 195 vehicle # => #<Vehicle:0xb7cf4eac @state="second_gear", @seatbelt_on=true>
179ce54f » obrie 2008-07-05 Add more descriptive except... 196
197 # The bang (!) operator can raise exceptions if the event fails
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 198 vehicle.park! # => StateMachine::InvalidTransition: Cannot transition state via :park from :second_gear
48d83dfb » obrie 2008-12-14 Add generic attribute predi... Comment 199
200 # Generic state predicates can raise exceptions if the value does not exist
17b472ca » obrie 2009-03-21 Add #fire_events / #fire_ev... 201 vehicle.state?(:parked) # => false
e616242d » obrie 2009-04-04 Fix README examples 202 vehicle.state?(:invalid) # => IndexError: :invalid is an invalid name
cfa7757d » obrie 2008-12-17 Add :namespace option for g... 203
204 # Namespaced machines have uniquely-generated methods
09a2e3cd » obrie 2009-03-21 Move methods related to mul... 205 vehicle.alarm_state # => 1
206 vehicle.alarm_state_name # => :active
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 207
09a2e3cd » obrie 2009-03-21 Move methods related to mul... 208 vehicle.can_disable_alarm? # => true
209 vehicle.disable_alarm # => true
210 vehicle.alarm_state # => 0
211 vehicle.alarm_state_name # => :off
212 vehicle.can_enable_alarm? # => true
cfa7757d » obrie 2008-12-17 Add :namespace option for g... 213
e616242d » obrie 2009-04-04 Fix README examples 214 vehicle.alarm_off? # => true
215 vehicle.alarm_active? # => false
17b472ca » obrie 2009-03-21 Add #fire_events / #fire_ev... 216
217 # Events can be fired in parallel
09a2e3cd » obrie 2009-03-21 Move methods related to mul... 218 vehicle.fire_events(:shift_down, :enable_alarm) # => true
17b472ca » obrie 2009-03-21 Add #fire_events / #fire_ev... 219 vehicle.state_name # => :first_gear
09a2e3cd » obrie 2009-03-21 Move methods related to mul... 220 vehicle.alarm_state_name # => :active
17b472ca » obrie 2009-03-21 Add #fire_events / #fire_ev... 221
e616242d » obrie 2009-04-04 Fix README examples 222 vehicle.fire_events!(:ignite, :enable_alarm) # => StateMachine::InvalidTransition: Cannot run events in parallel: ignite, enable_alarm
6a94afcc » obrie 2008-09-06 MAJOR REWRITE! Replace all ... Comment 223
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 224 == Integrations
225
226 In addition to being able to define state machines on all Ruby classes, a set of
227 out-of-the-box integrations are available for some of the more popular Ruby
228 libraries. These integrations add library-specific behavior, allowing for state
229 machines to work more tightly with the conventions defined by those libraries.
230
231 The integrations currently available include:
232 * ActiveRecord models
233 * DataMapper resources
b68d4bda » obrie 2008-12-14 Add Sequel support 234 * Sequel models
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 235
236 A brief overview of these integrations is described below.
237
238 === ActiveRecord
239
240 The ActiveRecord integration adds support for database transactions, automatically
8c843f01 » obrie 2009-03-07 Add a validation error when... 241 saving the record, named scopes, validation errors, and observers. For example,
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 242
243 class Vehicle < ActiveRecord::Base
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 244 state_machine :initial => :parked do
7f7037e4 » obrie 2009-03-08 Tweak callback examples 245 before_transition :parked => any - :parked, :do => :put_on_seatbelt
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 246 after_transition any => :parked do |vehicle, transition|
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 247 vehicle.seatbelt = 'off'
248 end
249
250 event :ignite do
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 251 transition :parked => :idling
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 252 end
9508a446 » obrie 2009-03-03 Add support state-driven cl... 253
254 state :first_gear, :second_gear do
255 validates_presence_of :seatbelt_on
256 end
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 257 end
258
259 def put_on_seatbelt
260 ...
261 end
262 end
263
264 class VehicleObserver < ActiveRecord::Observer
265 # Callback for :ignite event *before* the transition is performed
266 def before_ignite(vehicle, transition)
267 # log message
268 end
269
2623e4d3 » obrie 2009-04-05 Tweak README docs 270 # Generic transition callback *after* the transition is performed
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 271 def after_transition(vehicle, transition)
272 Audit.log(vehicle, transition)
273 end
274 end
275
276 For more information about the various behaviors added for ActiveRecord state
146afff4 » obrie 2008-12-14 Remove the PluginAWeek name... 277 machines, see StateMachine::Integrations::ActiveRecord.
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 278
279 === DataMapper
280
281 Like the ActiveRecord integration, the DataMapper integration adds support for
282 database transactions, automatically saving the record, named scopes, Extlib-like
8c843f01 » obrie 2009-03-07 Add a validation error when... 283 callbacks, validation errors, and observers. For example,
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 284
285 class Vehicle
286 include DataMapper::Resource
287
288 property :id, Serial
289 property :state, String
290
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 291 state_machine :initial => :parked do
7f7037e4 » obrie 2009-03-08 Tweak callback examples 292 before_transition :parked => any - :parked, :do => :put_on_seatbelt
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 293 after_transition any => :parked do |transition|
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 294 self.seatbelt = 'off' # self is the record
295 end
296
297 event :ignite do
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 298 transition :parked => :idling
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 299 end
9508a446 » obrie 2009-03-03 Add support state-driven cl... 300
301 state :first_gear, :second_gear do
b3b2c56b » obrie 2009-03-03 Fix DataMapper example in R... 302 validates_present :seatbelt_on
9508a446 » obrie 2009-03-03 Add support state-driven cl... 303 end
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 304 end
305
306 def put_on_seatbelt
307 ...
308 end
309 end
310
311 class VehicleObserver
312 include DataMapper::Observer
313
314 observe Vehicle
315
316 # Callback for :ignite event *before* the transition is performed
317 before_transition :on => :ignite do |transition|
318 # log message (self is the record)
319 end
320
2623e4d3 » obrie 2009-04-05 Tweak README docs 321 # Generic transition callback *after* the transition is performed
804b02a5 » obrie 2009-03-28 Add support for targeting m... 322 after_transition do |transition|
323 Audit.log(self, transition) # self is the record
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 324 end
325 end
326
bae9e169 » obrie 2008-12-28 Allow dm-observer integrati... 327 *Note* that the DataMapper::Observer integration is optional and only available
328 when the dm-observer library is installed.
329
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 330 For more information about the various behaviors added for DataMapper state
146afff4 » obrie 2008-12-14 Remove the PluginAWeek name... 331 machines, see StateMachine::Integrations::DataMapper.
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 332
b68d4bda » obrie 2008-12-14 Add Sequel support 333 === Sequel
334
335 Like the ActiveRecord integration, the Sequel integration adds support for
8c843f01 » obrie 2009-03-07 Add a validation error when... 336 database transactions, automatically saving the record, named scopes, validation
337 errors and callbacks. For example,
b68d4bda » obrie 2008-12-14 Add Sequel support 338
339 class Vehicle < Sequel::Model
b9d0ccc4 » obrie 2009-01-10 Add support for customizing... 340 state_machine :initial => :parked do
7f7037e4 » obrie 2009-03-08 Tweak callback examples 341 before_transition :parked => any - :parked, :do => :put_on_seatbelt
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 342 after_transition any => :parked do |transition|
b68d4bda » obrie 2008-12-14 Add Sequel support 343 self.seatbelt = 'off' # self is the record
344 end
345
346 event :ignite do
cdec7f2d » obrie 2009-03-02 Add simplified transition/c... 347 transition :parked => :idling
b68d4bda » obrie 2008-12-14 Add Sequel support 348 end
9508a446 » obrie 2009-03-03 Add support state-driven cl... 349
350 state :first_gear, :second_gear do
351 validates_presence_of :seatbelt_on
352 end
b68d4bda » obrie 2008-12-14 Add Sequel support 353 end
354
355 def put_on_seatbelt
356 ...
357 end
358 end
359
360 For more information about the various behaviors added for Sequel state
146afff4 » obrie 2008-12-14 Remove the PluginAWeek name... 361 machines, see StateMachine::Integrations::Sequel.
b68d4bda » obrie 2008-12-14 Add Sequel support 362
a25b0da9 » obrie 2009-03-03 Add compatibility section i... 363 == Compatibility
364
365 Although state_machine introduces a simplified syntax, it still remains
366 backwards compatible with previous versions and other state-related libraries.
367 For example, transitions and callbacks can continue to be defined like so:
368
369 class Vehicle
370 state_machine :initial => :parked do
7f7037e4 » obrie 2009-03-08 Tweak callback examples 371 before_transition :from => :parked, :except_to => :parked, :do => :put_on_seatbelt
a25b0da9 » obrie 2009-03-03 Add compatibility section i... 372 after_transition :to => :parked do |transition|
373 self.seatbelt = 'off' # self is the record
374 end
375
376 event :ignite do
377 transition :from => :parked, :to => :idling
378 end
379 end
380 end
381
382 Although this verbose syntax will most likely always be supported, it is
383 recommended that any state machines eventually migrate to the syntax introduced
384 in version 0.6.0.
385
b5066674 » obrie 2007-09-21 Move test fixtures out of t... 386 == Tools
387
6f25124e » jashmenn 2008-12-08 Add rake tasks for generati... Comment 388 === Generating graphs
389
390 This library comes with built-in support for generating di-graphs based on the
391 events, states, and transitions defined for a state machine using GraphViz[http://www.graphviz.org].
392 This requires that both the <tt>ruby-graphviz</tt> gem and graphviz library be
393 installed on the system.
394
395 ==== Examples
396
397 To generate a graph for a specific file / class:
398
399 rake state_machine:draw FILE=vehicle.rb CLASS=Vehicle
400
401 To save files to a specific path:
402
403 rake state_machine:draw FILE=vehicle.rb CLASS=Vehicle TARGET=files
404
51306ac5 » obrie 2009-03-10 Add support for customizing... 405 To customize the image format / orientation:
6f25124e » jashmenn 2008-12-08 Add rake tasks for generati... Comment 406
51306ac5 » obrie 2009-03-10 Add support for customizing... 407 rake state_machine:draw FILE=vehicle.rb CLASS=Vehicle FORMAT=jpg ORIENTATION=landscape
6f25124e » jashmenn 2008-12-08 Add rake tasks for generati... Comment 408
409 To generate multiple state machine graphs:
410
411 rake state_machine:draw FILE=vehicle.rb,car.rb CLASS=Vehicle,Car
412
413 *Note* that this will generate a different file for every state machine defined
0b8609e7 » obrie 2008-12-15 Tweak README 414 in the class. The generated files will use an output filename of the format
211763da » obrie 2009-06-14 Minor doc fixes 415 #{class_name}_#{machine_name}.#{format}.
6f25124e » jashmenn 2008-12-08 Add rake tasks for generati... Comment 416
417 For examples of actual images generated using this task, see those under the
0b8609e7 » obrie 2008-12-15 Tweak README 418 examples folder.
6f25124e » jashmenn 2008-12-08 Add rake tasks for generati... Comment 419
420 ==== Ruby on Rails Integration
421
422 There is a special integration Rake task for generating state machines for
423 classes used in a Ruby on Rails application. This task will load the application
424 environment, meaning that it's unnecessary to specify the actual file to load.
425
426 For example,
427
428 rake state_machine:draw:rails CLASS=Vehicle
429
430 ==== Merb Integration
431
432 Like Ruby on Rails, there is a special integration Rake task for generating
433 state machines for classes used in a Merb application. This task will load the
434 application environment, meaning that it's unnecessary to specify the actual
435 files to load.
436
437 For example,
438
439 rake state_machine:draw:merb CLASS=Vehicle
440
441 === Interactive graphs
442
8563ca6b » obrie 2007-09-21 More documentation 443 Jean Bovet - {Visual Automata Simulator}[http://www.cs.usfca.edu/~jbovet/vas.html].
444 This is a great tool for "simulating, visualizing and transforming finite state
445 automata and Turing Machines". This tool can help in the creation of states and
446 events for your models. It is cross-platform, written in Java.
b5066674 » obrie 2007-09-21 Move test fixtures out of t... 447
f3565041 » obrie 2008-05-04 Completely rewritten from s... 448 == Testing
449
48d83dfb » obrie 2008-12-14 Add generic attribute predi... Comment 450 To run the entire test suite (will test ActiveRecord, DataMapper, and Sequel
0b8609e7 » obrie 2008-12-15 Tweak README 451 integrations if the proper dependencies are available):
594ad289 » obrie 2008-05-12 Add information about what ... 452
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 453 rake test
594ad289 » obrie 2008-05-12 Add information about what ... 454
59e0ea49 » obrie 2009-03-07 Add docs on testing specifi... 455 Target specific versions of integrations like so:
456
03e413c3 » obrie 2009-04-25 Require DataMapper version ... 457 rake test AR_VERSION=2.1.0 DM_VERSION=0.9.4 SEQUEL_VERSION=2.8.0
59e0ea49 » obrie 2009-03-07 Add docs on testing specifi... 458
594ad289 » obrie 2008-05-12 Add information about what ... 459 == Dependencies
460
307ac8eb » obrie 2008-12-07 Re-design to be library-agn... 461 By default, there are no dependencies. If using specific integrations, those
462 dependencies are listed below.
463
464 * ActiveRecord[http://rubyonrails.org] integration: 2.1.0 or later
03e413c3 » obrie 2009-04-25 Require DataMapper version ... 465 * DataMapper[http://datamapper.org] integration: 0.9.4 or later
b68d4bda » obrie 2008-12-14 Add Sequel support 466 * Sequel[http://sequel.rubyforge.org] integration: 2.8.0 or later