@@ -342,6 +342,8 @@ Advanced usage
342
342
You can easily reflect on workflow specification programmatically - for
343
343
the whole class or for the current object. Examples:
344
344
345
+ include::test/reflection_test.rb[tag=reflect]
346
+
345
347
article2.current_state.events # lists possible events from here
346
348
article2.current_state.events[:reject].transitions_to # => :rejected
347
349
@@ -375,18 +377,20 @@ representation of the workflow. See below.
375
377
376
378
Conditions can be a "method name symbol" with a corresponding instance method, a `proc` or `lambda` which are added to events, like so:
377
379
378
- state :off
379
- event :turn_on, :transition_to => :on,
380
- :if => :sufficient_battery_level?
380
+ ....
381
+ state :off
382
+ event :turn_on, :transition_to => :on,
383
+ :if => :sufficient_battery_level?
381
384
382
- event :turn_on, :transition_to => :low_battery,
383
- :if => proc { |device| device.battery_level > 0 }
384
- end
385
+ event :turn_on, :transition_to => :low_battery,
386
+ :if => proc { |device| device.battery_level > 0 }
387
+ end
385
388
386
- # corresponding instance method
387
- def sufficient_battery_level?
388
- battery_level > 10
389
- end
389
+ # corresponding instance method
390
+ def sufficient_battery_level?
391
+ battery_level > 10
392
+ end
393
+ ....
390
394
391
395
When calling a `device.can_<fire_event>?` check, or attempting a `device.<event>!`, each event is checked in turn:
392
396
0 commit comments