public
Description: An extendable, cloneable, dynamic UML 2 StateMachine for Ruby
Homepage: http://kurtstephens.com
Clone URL: git://github.com/kstephens/red_steak.git
UML uses State#entry not State#enter.
kstephens (author)
Tue Dec 30 23:09:38 -0800 2008
commit  1bdd51a3216fb5cc8e5d3403412d946674cba6b7
tree    483b8d66a357007ce5ee8b1ded1df6e500df5737
parent  59bdbe3cf423936f5ffb6cf905422ceb9d4d585c
0
...
3
4
5
6
7
8
9
10
11
...
3
4
5
 
6
 
7
8
9
0
@@ -3,9 +3,7 @@
0
 
0
 * Things to do:
0
 ** Machine#state=(String|Array).
0
-** Trigger State#enter and State#exit on superstates for transitions between Substates with disjoint superstates.
0
 ** Add :elapsed_time to history Hash - has performance implication.
0
-** Use UML nomenclature for can_transition?, before_transition!, after_transition!: i.e.: :guard and triggers (enter, exit).
0
 ** Support Statemachine#freeze to avoid accidental changes to a running Statemachine.
0
 
0
 * Jeremy's Comments:
...
26
27
28
29
 
30
31
32
...
287
288
289
290
 
291
292
293
...
337
338
339
340
 
341
342
343
...
367
368
369
370
 
371
372
373
374
 
 
375
376
377
...
26
27
28
 
29
30
31
32
...
287
288
289
 
290
291
292
293
...
337
338
339
 
340
341
342
343
...
367
368
369
 
370
371
372
 
 
373
374
375
376
377
0
@@ -26,7 +26,7 @@ module RedSteak
0
     # * guard(machine, trans, *args)
0
     # * effect(machine, trans, *args)
0
     #
0
-    # * enter(machine, state, *args)
0
+    # * entry(machine, state, *args)
0
     # * exit(machine, state, *args)
0
     # * doActivity(machine, state, *args)
0
     #
0
@@ -287,7 +287,7 @@ module RedSteak
0
     # 1) Transition's effect behavior is performed.
0
     # 2) Old State's exit behavior is performed.
0
     # 3) transition history is logged.
0
-    # 4) New State's enter behavior is performed.
0
+    # 4) New State's entry behavior is performed.
0
     # 5) New State's doAction behavior is performed.
0
     #
0
     def execute_transition! trans, *args
0
@@ -337,7 +337,7 @@ module RedSteak
0
     #
0
     # 1) Performs old State's exit behavior.
0
     # 2) If a block is given, yield to it after entering new state.
0
-    # 3) Performs new State's enter behavior.
0
+    # 3) Performs new State's entry behavior.
0
     #
0
     def _goto_state! state, args
0
       old_state = @state
0
@@ -367,11 +367,11 @@ module RedSteak
0
       # Yield to block.
0
       yield if block_given?
0
       
0
-      # Behavior: enter state.
0
+      # Behavior: entry state.
0
       if old_state != state
0
         (to - from).reverse.each do | s | 
0
-          _log "enter! #{s.inspect}"
0
-          s.enter!(self, args)
0
+          _log "entry! #{s.inspect}"
0
+          s.entry!(self, args)
0
         end
0
       end
0
 
...
8
9
10
11
12
13
14
 
15
16
17
18
 
 
 
19
20
21
22
23
24
25
 
26
27
28
...
130
131
132
133
134
 
 
135
136
137
...
8
9
10
 
 
 
 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
25
26
27
28
...
130
131
132
 
 
133
134
135
136
137
0
@@ -8,21 +8,21 @@ module RedSteak
0
     attr_accessor :state_type # NOT UML AT ALL
0
 
0
     # The behavior executed upon entry to the transtion.
0
-    attr_accessor :enter
0
-
0
-    # The behavior executed when it is transitioned into.
0
-    attr_accessor :doActivity
0
+    attr_accessor :entry
0
 
0
     # The behavior executed when it is transitioned out of.
0
     attr_accessor :exit
0
 
0
+    # The behavior executed when it is transitioned into.
0
+    attr_accessor :doActivity
0
+
0
     # This state's submachine, or nil.
0
     attr_accessor :submachine # UML
0
 
0
 
0
     def initialize opts = { }
0
       @state_type = nil
0
-      @enter = nil
0
+      @entry = nil
0
       @doActivity = nil
0
       @exit = nil
0
       @submachine = nil
0
@@ -130,8 +130,8 @@ module RedSteak
0
 
0
 
0
     # Called by Machine when State is entered.
0
-    def enter! machine, args
0
-      _behavior! :enter, machine, args
0
+    def entry! machine, args
0
+      _behavior! :entry, machine, args
0
     end
0
 
0
 
...
12
13
14
15
 
16
17
18
...
33
34
35
36
 
37
38
39
...
63
64
65
66
67
 
 
68
69
70
71
 
72
73
74
...
121
122
123
124
 
125
126
127
...
304
305
306
307
 
308
309
310
...
327
328
329
330
 
331
332
333
...
510
511
512
513
 
514
515
516
...
609
610
611
612
 
613
614
615
616
617
 
618
619
620
621
622
 
623
624
625
626
627
 
628
629
630
631
632
 
633
634
635
...
12
13
14
 
15
16
17
18
...
33
34
35
 
36
37
38
39
...
63
64
65
 
 
66
67
68
69
70
 
71
72
73
74
...
121
122
123
 
124
125
126
127
...
304
305
306
 
307
308
309
310
...
327
328
329
 
330
331
332
333
...
510
511
512
 
513
514
515
516
...
609
610
611
 
612
613
614
615
616
 
617
618
619
620
621
 
622
623
624
625
626
 
627
628
629
630
631
 
632
633
634
635
0
@@ -12,7 +12,7 @@ describe RedSteak do
0
     attr_accessor :_transition, :_guard, :_effect
0
 
0
     # State Behaviors:
0
-    attr_accessor :_state, :_enter, :_exit, :_doActivity
0
+    attr_accessor :_state, :_entry, :_exit, :_doActivity
0
 
0
     attr_accessor :_a_to_b
0
 
0
@@ -33,7 +33,7 @@ describe RedSteak do
0
       @_guard = [ ]
0
       @_effect = [ ]
0
       @_state = [ ]
0
-      @_enter = [ ]
0
+      @_entry = [ ]
0
       @_exit = [ ] 
0
       @_doActivity = [ ]
0
     end
0
@@ -63,12 +63,12 @@ describe RedSteak do
0
       _log
0
     end
0
 
0
-    # Called by State#enter!
0
-    def enter(machine, state, *args)
0
+    # Called by State#entry!
0
+    def entry(machine, state, *args)
0
       @_machine = machine
0
       @_state = state
0
       @_args = args
0
-      @_enter << [ state.to_s, *args ]
0
+      @_entry << [ state.to_s, *args ]
0
       _log
0
     end
0
 
0
@@ -121,7 +121,7 @@ describe RedSteak do
0
           :name => :a_to_b,
0
           :guard => :a_to_b?
0
     
0
-  # state :q, :enter_state => :entering_q
0
+  # state :q, :entry_state => :entrying_q
0
         
0
         state :b
0
         transition :c
0
@@ -304,7 +304,7 @@ describe RedSteak do
0
     c._transition.should == nil
0
     c._guard.should == [ ]
0
     c._effect.should == [ ]
0
-    c._enter.should == [ [ "a" ] ]
0
+    c._entry.should == [ [ "a" ] ]
0
     c._exit.should == [ ]
0
     c._doActivity.should == [ [ "a" ] ]
0
     m.history.size.should == 1
0
@@ -327,7 +327,7 @@ describe RedSteak do
0
     c._a_to_b.should == [ :arg1 ]
0
     c._effect.should == [ [ :arg1 ] ]
0
     c._state.name.should == :b
0
-    c._enter.should == [ [ "b", :arg1 ] ]
0
+    c._entry.should == [ [ "b", :arg1 ] ]
0
     c._exit.should == [ [ "a", :arg1 ] ]
0
     c._doActivity.should == [ [ "b", :arg1 ] ]
0
     m.history.size.should == 2
0
@@ -510,7 +510,7 @@ describe RedSteak do
0
     m.state.name.should == :a
0
     c._machine.should == m
0
     c._state.name.should == :a
0
-    c._enter.should == [ [ "a", :foo, :bar ] ]
0
+    c._entry.should == [ [ "a", :foo, :bar ] ]
0
     c._exit.should == [ ]
0
  
0
     render_graph m, :show_history => true
0
@@ -609,27 +609,27 @@ describe RedSteak do
0
     c.clear!
0
     m.start!
0
     c._exit.should == [ ]
0
-    c._enter.should == [ [ "a" ], [ "a::a" ] ]
0
+    c._entry.should == [ [ "a" ], [ "a::a" ] ]
0
 
0
     c.clear!
0
     m.transition_to! "b"
0
     c._exit.should == [["a::a"], ["a"]]
0
-    c._enter.should == [ [ "b" ], [ "b::a" ] ]
0
+    c._entry.should == [ [ "b" ], [ "b::a" ] ]
0
 
0
     c.clear!
0
     m.transition_to! "b::b"
0
     c._exit.should == [["b::a"]]
0
-    c._enter.should == [["b::b"]]
0
+    c._entry.should == [["b::b"]]
0
 
0
     c.clear!
0
     m.transition_to! "a::b"
0
     c._exit.should == [["b::b"], ["b"]]
0
-    c._enter.should == [["a"], ["a::b"]] 
0
+    c._entry.should == [["a"], ["a::b"]] 
0
 
0
     c.clear!
0
     m.transition_to! "c"
0
     c._exit.should == [["a::b"], ["a"]]
0
-    c._enter.should == [["c"]]
0
+    c._entry.should == [["c"]]
0
 
0
     render_graph m, :show_history => true
0
 

Comments