public
Description: Shade is a state machine (or workflow) engine for ColdFusion business objects.
Homepage:
Clone URL: git://github.com/ryanwood/shade.git
Added global event callbacks with tests
ryanwood (author)
Fri Sep 12 07:57:35 -0700 2008
commit  4c22d15ff9d74cfaf15153438ed0b4bb6ca7af08
tree    57a762ab00953a01ce374fadd3b4fccc495f933e
parent  a0424f7ec70c1d1f8a0d8c1d83097ef9b5b92d1c
...
16
17
18
 
19
20
21
22
23
 
24
 
25
26
27
28
29
 
30
31
32
...
16
17
18
19
20
21
22
23
 
24
25
26
27
28
29
30
31
32
33
34
35
0
@@ -16,17 +16,20 @@
0
   
0
   <cffunction name="before" returntype="boolean" access="public" output="false">
0
     <cfargument name="obj" required="true" />
0
+    <cfset invokeCallback('beforeAction', arguments.obj) />
0
     <cfreturn invokeCallback('before#getName()#Action', arguments.obj) />
0
   </cffunction>
0
   
0
   <cffunction name="after" returntype="void" access="public" output="false">
0
-    <cfargument name="obj" required="true" />
0
+    <cfargument name="obj" required="true" />    
0
     <cfset invokeCallback('after#getName()#Action', arguments.obj) />
0
+    <cfset invokeCallback('afterAction', arguments.obj) />
0
   </cffunction>  
0
   
0
   <cffunction name="exit" returntype="void" access="public" output="false">
0
     <cfargument name="obj" required="true" />
0
     <cfset invokeCallback('exit#getName()#Action', arguments.obj) />
0
+    <cfset invokeCallback('exitAction', arguments.obj) />
0
   </cffunction>
0
   
0
   <cffunction name="invokeCallback" returntype="boolean" access="private" output="false">
...
3
4
5
 
6
7
8
...
88
89
90
 
 
 
 
 
 
 
 
91
92
93
...
3
4
5
6
7
8
9
...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
0
@@ -3,6 +3,7 @@
0
 
0
   <cffunction name="init" access="public" returntype="any" output="false" hint="">
0
     <cfset instance.state = '' />
0
+    <cfset instance.beforeActionCount = 0 />
0
     <cfreturn this />
0
   </cffunction>
0
     
0
@@ -88,5 +89,13 @@
0
     <cfargument name="value" type="boolean" required="true" />
0
     <cfset instance.readExit = arguments.value />
0
   </cffunction>  
0
+  
0
+  <cffunction name="incrementBeforeActionCount" access="public" returntype="void" output="false">
0
+    <cfset instance.beforeActionCount = instance.beforeActionCount + 1 />
0
+  </cffunction>  
0
+  
0
+  <cffunction name="getBeforeActionCount" access="public" returntype="Numeric" output="false">
0
+    <cfreturn instance.beforeActionCount />
0
+  </cffunction>  
0
 
0
 </cfcomponent>
0
\ No newline at end of file
...
57
58
59
 
 
 
 
60
61
62
...
57
58
59
60
61
62
63
64
65
66
0
@@ -57,5 +57,9 @@
0
   <cffunction name="afterClosedAction" access="public" returntype="void" output="false">
0
     <cfset getOriginalObject().setClosedAfter(true) />
0
   </cffunction>
0
+  
0
+  <cffunction name="beforeAction" access="public" returntype="void" output="false">
0
+    <cfset getOriginalObject().incrementBeforeActionCount() />
0
+  </cffunction>
0
 
0
 </cfcomponent>
0
\ No newline at end of file
...
221
222
223
 
 
 
 
 
 
 
 
 
 
 
224
225
...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
0
@@ -221,4 +221,15 @@
0
     </cfscript>
0
   </cffunction>
0
   
0
+  <cffunction name="testGlobalBeforeActionExecuted" returntype="void" access="public" output="false">
0
+    <cfscript>
0
+      // Should be 1 because it has to set the initial state
0
+      assertEquals(1, conversation.getBeforeActionCount());
0
+      conversation.view();
0
+      assertEquals(2, conversation.getBeforeActionCount());
0
+      conversation.reply();
0
+      assertEquals(3, conversation.getBeforeActionCount());
0
+    </cfscript>
0
+  </cffunction>
0
+  
0
 </cfcomponent>
0
\ No newline at end of file

Comments