Capcode 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/README.rdoc +58 -0
  2. data/doc/rdoc/classes/Capcode.html +938 -0
  3. data/doc/rdoc/classes/Capcode/Base.html +136 -0
  4. data/doc/rdoc/classes/Capcode/HTTPError.html +134 -0
  5. data/doc/rdoc/classes/Capcode/Helpers.html +608 -0
  6. data/doc/rdoc/classes/Capcode/Helpers/Authorization.html +188 -0
  7. data/doc/rdoc/classes/Capcode/Mab.html +118 -0
  8. data/doc/rdoc/classes/Capcode/Resource.html +111 -0
  9. data/doc/rdoc/classes/Capcode/Views.html +112 -0
  10. data/doc/rdoc/created.rid +1 -0
  11. data/doc/rdoc/files/AUTHORS.html +107 -0
  12. data/doc/rdoc/files/COPYING.html +531 -0
  13. data/doc/rdoc/files/README_rdoc.html +601 -0
  14. data/doc/rdoc/files/lib/capcode/base/db_rb.html +101 -0
  15. data/doc/rdoc/files/lib/capcode/helpers/auth_rb.html +132 -0
  16. data/doc/rdoc/files/lib/capcode/render/erb_rb.html +108 -0
  17. data/doc/rdoc/files/lib/capcode/render/haml_rb.html +108 -0
  18. data/doc/rdoc/files/lib/capcode/render/json_rb.html +108 -0
  19. data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +108 -0
  20. data/doc/rdoc/files/lib/capcode/render/sass_rb.html +108 -0
  21. data/doc/rdoc/files/lib/capcode/render/static_rb.html +101 -0
  22. data/doc/rdoc/files/lib/capcode/render/text_rb.html +101 -0
  23. data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +124 -0
  24. data/doc/rdoc/files/lib/capcode/render/xml_rb.html +101 -0
  25. data/doc/rdoc/files/lib/capcode_rb.html +119 -0
  26. data/doc/rdoc/fr_class_index.html +34 -0
  27. data/doc/rdoc/fr_file_index.html +41 -0
  28. data/doc/rdoc/fr_method_index.html +44 -0
  29. data/doc/rdoc/index.html +24 -0
  30. data/doc/rdoc/rdoc-style.css +208 -0
  31. data/examples/auth-basic.rb +46 -0
  32. data/examples/auth-digest.rb +47 -0
  33. data/examples/auth-webdav.rb +29 -0
  34. data/examples/blog-couchdb-run.rb +10 -0
  35. data/examples/blog-couchdb.rb +8 -8
  36. data/examples/blog-couchdb.ru +12 -0
  37. data/examples/render-static.rb +1 -1
  38. data/examples/render-static.ru +21 -0
  39. data/examples/render-webdav.rb +26 -0
  40. data/examples/rest-run.rb +3 -0
  41. data/examples/rest.rb +1 -1
  42. data/examples/rest.ru +3 -0
  43. data/lib/capcode.rb +196 -100
  44. data/lib/capcode/helpers/auth.rb +130 -0
  45. data/lib/capcode/render/webdav.rb +45 -0
  46. data/lib/capcode/version.rb +1 -1
  47. metadata +45 -3
@@ -12,6 +12,12 @@ Capcode is a web microframework
12
12
 
13
13
  == FEATURES/PROBLEMS:
14
14
 
15
+ === 0.8.5
16
+ * Capcode now work with Phusion Passenger \o/
17
+ * Add WebDAV renderer (need rack_dav) (see examples render-webdav.rb and auth-webdav.rb)
18
+ * Change default listen host from localhost to 0.0.0.0
19
+ * Add require_auth helper for basic or digest HTTP Authentication (see examples auth-basic.rb and auth-digest.rb)
20
+
15
21
  === 0.8.4
16
22
  * Major (really MAJOR) bugs corrections in renderers
17
23
  * Add many renderer' examples
@@ -254,6 +260,58 @@ See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for co
254
260
 
255
261
  Capcode.run( )
256
262
 
263
+ === Render with WebDAV
264
+
265
+ # file: sample.rb
266
+ require 'rubygems'
267
+ require 'capcode'
268
+ require 'capcode/render/webdav'
269
+
270
+ module Capcode
271
+
272
+ # !!! Render file from /Users/greg/temp !!!
273
+ class WebDav < Route '/temp'
274
+ def get
275
+ render :webdav => "/Users/greg"
276
+ end
277
+
278
+ def method_missing(id, *a, &b)
279
+ get
280
+ end
281
+ end
282
+
283
+ class Index < Route '/'
284
+ def get
285
+ render "WebDav server acces : <a href='#{URL(Capcode::WebDav)}'>#{URL(Capcode::WebDav)}</a>"
286
+ end
287
+ end
288
+
289
+ end
290
+
291
+ Capcode.run( )
292
+
293
+ == DEPLOYMENT
294
+
295
+ === With Passenger
296
+
297
+ First create the directory structure :
298
+
299
+ my_app/
300
+ my_app/tmp
301
+ my_app/public
302
+
303
+ Then put your app in <tt>my_app/</tt> and comment or remove the line with <tt>Capcode.run</tt>
304
+
305
+ Create a rack configuration file (<tt>config.ru</tt>) in <tt>my_app/</tt>
306
+
307
+ require 'app'
308
+ run Capcode.application()
309
+
310
+ <tt>Capcode.application</tt> take the same parameters as <tt>Capcode.run</tt> (and block too). Be carefull, if you use
311
+ static files (with the static renderer) you must set the <tt>:root</tt> option (<tt>:root => File.expand_path(File.dirname(__FILE__))</tt> is probably good)
312
+
313
+ You can now deploy your application like a {"Rack-based Ruby application"}[http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application]
314
+
257
315
  == REQUIREMENTS:
258
316
 
259
317
  * rack
@@ -0,0 +1,938 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Capcode</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Capcode</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/capcode_rb.html">
59
+ lib/capcode.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/capcode/base/db_rb.html">
63
+ lib/capcode/base/db.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/capcode/render/erb_rb.html">
67
+ lib/capcode/render/erb.rb
68
+ </a>
69
+ <br />
70
+ <a href="../files/lib/capcode/render/haml_rb.html">
71
+ lib/capcode/render/haml.rb
72
+ </a>
73
+ <br />
74
+ <a href="../files/lib/capcode/render/json_rb.html">
75
+ lib/capcode/render/json.rb
76
+ </a>
77
+ <br />
78
+ <a href="../files/lib/capcode/render/markaby_rb.html">
79
+ lib/capcode/render/markaby.rb
80
+ </a>
81
+ <br />
82
+ <a href="../files/lib/capcode/render/sass_rb.html">
83
+ lib/capcode/render/sass.rb
84
+ </a>
85
+ <br />
86
+ <a href="../files/lib/capcode/render/static_rb.html">
87
+ lib/capcode/render/static.rb
88
+ </a>
89
+ <br />
90
+ <a href="../files/lib/capcode/render/text_rb.html">
91
+ lib/capcode/render/text.rb
92
+ </a>
93
+ <br />
94
+ <a href="../files/lib/capcode/render/webdav_rb.html">
95
+ lib/capcode/render/webdav.rb
96
+ </a>
97
+ <br />
98
+ <a href="../files/lib/capcode/render/xml_rb.html">
99
+ lib/capcode/render/xml.rb
100
+ </a>
101
+ <br />
102
+ <a href="../files/lib/capcode/helpers/auth_rb.html">
103
+ lib/capcode/helpers/auth.rb
104
+ </a>
105
+ <br />
106
+ </td>
107
+ </tr>
108
+
109
+ </table>
110
+ </div>
111
+ <!-- banner header -->
112
+
113
+ <div id="bodyContent">
114
+
115
+
116
+
117
+ <div id="contextContent">
118
+
119
+ <div id="description">
120
+ <p>
121
+ Because this helper was trully inspired by this post : <a
122
+ href="http://www.gittr.com/index.php/archive/sinatra-basic-authentication-selectively-applied">www.gittr.com/index.php/archive/sinatra-basic-authentication-selectively-applied</a>/
123
+ and because the code in this post was extracted out of Wink, this file
124
+ follow the Wink license :
125
+ </p>
126
+ <p>
127
+ Permission is hereby granted, free of charge, to any person obtaining a
128
+ copy of this software and associated documentation files (the
129
+ &quot;Software&quot;), to deal in the Software without restriction,
130
+ including without limitation the rights to use, copy, modify, merge,
131
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
132
+ permit persons to whom the Software is furnished to do so, subject to the
133
+ following conditions:
134
+ </p>
135
+ <p>
136
+ The above copyright notice and this permission notice shall be included in
137
+ all copies or substantial portions of the Software.
138
+ </p>
139
+ <p>
140
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
141
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
142
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
143
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
144
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
145
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
146
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
147
+ </p>
148
+
149
+ </div>
150
+
151
+
152
+ </div>
153
+
154
+ <div id="method-list">
155
+ <h3 class="section-bar">Methods</h3>
156
+
157
+ <div class="name-list">
158
+ <a href="#M000001">Route</a>&nbsp;&nbsp;
159
+ <a href="#M000009">application</a>&nbsp;&nbsp;
160
+ <a href="#M000003">env</a>&nbsp;&nbsp;
161
+ <a href="#M000008">http_authentication</a>&nbsp;&nbsp;
162
+ <a href="#M000007">map</a>&nbsp;&nbsp;
163
+ <a href="#M000002">params</a>&nbsp;&nbsp;
164
+ <a href="#M000005">request</a>&nbsp;&nbsp;
165
+ <a href="#M000006">response</a>&nbsp;&nbsp;
166
+ <a href="#M000010">run</a>&nbsp;&nbsp;
167
+ <a href="#M000004">session</a>&nbsp;&nbsp;
168
+ </div>
169
+ </div>
170
+
171
+ </div>
172
+
173
+
174
+ <!-- if includes -->
175
+ <div id="includes">
176
+ <h3 class="section-bar">Included Modules</h3>
177
+
178
+ <div id="includes-list">
179
+ <span class="include-name">Rack</span>
180
+ <span class="include-name"><a href="Capcode/Helpers.html">Capcode::Helpers</a></span>
181
+ <span class="include-name"><a href="Capcode/Views.html">Capcode::Views</a></span>
182
+ </div>
183
+ </div>
184
+
185
+ <div id="section">
186
+
187
+ <div id="class-list">
188
+ <h3 class="section-bar">Classes and Modules</h3>
189
+
190
+ Module <a href="Capcode/Helpers.html" class="link">Capcode::Helpers</a><br />
191
+ Module <a href="Capcode/Resource.html" class="link">Capcode::Resource</a><br />
192
+ Module <a href="Capcode/Views.html" class="link">Capcode::Views</a><br />
193
+ Class <a href="Capcode/Base.html" class="link">Capcode::Base</a><br />
194
+ Class <a href="Capcode/HTTPError.html" class="link">Capcode::HTTPError</a><br />
195
+ Class <a href="Capcode/Mab.html" class="link">Capcode::Mab</a><br />
196
+
197
+ </div>
198
+
199
+
200
+
201
+
202
+ <div id="attribute-list">
203
+ <h3 class="section-bar">Attributes</h3>
204
+
205
+ <div class="name-list">
206
+ <table>
207
+ <tr class="top-aligned-row context-row">
208
+ <td class="context-item-name">__auth__</td>
209
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
210
+ <td class="context-item-desc"></td>
211
+ </tr>
212
+ </table>
213
+ </div>
214
+ </div>
215
+
216
+
217
+
218
+ <!-- if method_list -->
219
+ <div id="methods">
220
+ <h3 class="section-bar">Public Class methods</h3>
221
+
222
+ <div id="method-M000001" class="method-detail">
223
+ <a name="M000001"></a>
224
+
225
+ <div class="method-heading">
226
+ <a href="#M000001" class="method-signature">
227
+ <span class="method-name">Route</span><span class="method-args">(*routes_paths)</span>
228
+ </a>
229
+ </div>
230
+
231
+ <div class="method-description">
232
+ <p>
233
+ Add routes to a controller class
234
+ </p>
235
+ <pre>
236
+ module Capcode
237
+ class Hello &lt; Route '/hello/(.*)', '/hello/([^#]*)#(.*)'
238
+ def get( arg1, arg2 )
239
+ ...
240
+ end
241
+ end
242
+ end
243
+ </pre>
244
+ <p>
245
+ In the <tt>get</tt> method, you will receive the maximum of parameters
246
+ declared by the routes. In this example, you will receive 2 parameters. So
247
+ if you go to <tt>/hello/world#friend</tt> then <tt>arg1</tt> will be set to
248
+ <tt>world</tt> and <tt>arg2</tt> will be set to <tt>friend</tt>. Now if you
249
+ go to <tt>/hello/you</tt>, then <tt>arg1</tt> will be set to <tt>you</tt>
250
+ and <tt>arg2</tt> will be set to <tt>nil</tt>
251
+ </p>
252
+ <p>
253
+ If the regexp in the route does not match, all arguments will be
254
+ <tt>nil</tt>
255
+ </p>
256
+ <p><a class="source-toggle" href="#"
257
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
258
+ <div class="method-source-code" id="M000001-source">
259
+ <pre>
260
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 284</span>
261
+ 284: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">routes_paths</span>
262
+ 285: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
263
+ 286: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
264
+ 287: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/</span>
265
+ 288: <span class="ruby-comment cmt"># # =&gt; [ {'/hello/world' =&gt; '([^\/]*)/id(\d*)', '/hello' =&gt; '(.*)'}, </span>
266
+ 289: <span class="ruby-comment cmt"># 2, </span>
267
+ 290: <span class="ruby-comment cmt"># &lt;Capcode::Klass&gt;, </span>
268
+ 291: <span class="ruby-comment cmt"># {:agent =&gt; /Songbird (\d\.\d)[\d\/]*?/} ]</span>
269
+ 292: <span class="ruby-identifier">hash_of_routes</span> = {}
270
+ 293: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
271
+ 294: <span class="ruby-identifier">routes_paths</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
272
+ 295: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current_route_path</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">String</span>
273
+ 296: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">current_route_path</span> )
274
+ 297: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
275
+ 298: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">&quot;Route `#{current_route_path}' already defined with regexp `#{hash_of_routes[current_route_path]}' !&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">current_route_path</span>)
276
+ 299: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
277
+ 300: <span class="ruby-keyword kw">else</span>
278
+ 301: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
279
+ 302: <span class="ruby-identifier">_pre</span> = <span class="ruby-value str">&quot;/&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">_pre</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
280
+ 303: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">&quot;Route `#{_pre}' already defined with regexp `#{hash_of_routes[_pre]}' !&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_pre</span>)
281
+ 304: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">_pre</span>] = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]
282
+ 305: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">max_captures_for_routes</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span>
283
+ 306: <span class="ruby-keyword kw">end</span>
284
+ 307: <span class="ruby-keyword kw">else</span>
285
+ 308: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-value str">&quot;Bad route declaration !&quot;</span>, <span class="ruby-identifier">caller</span>
286
+ 309: <span class="ruby-keyword kw">end</span>
287
+ 310: <span class="ruby-keyword kw">end</span>
288
+ 311: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
289
+ 312: }
290
+ 313:
291
+ 314: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
292
+ 315: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
293
+ 316: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
294
+ 317: <span class="ruby-keyword kw">end</span>
295
+ 318:
296
+ 319: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
297
+ 320: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
298
+ 321: <span class="ruby-ivar">@env</span>
299
+ 322: <span class="ruby-keyword kw">end</span>
300
+ 323:
301
+ 324: <span class="ruby-comment cmt"># Session hash</span>
302
+ 325: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
303
+ 326: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
304
+ 327: <span class="ruby-keyword kw">end</span>
305
+ 328:
306
+ 329: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
307
+ 330: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
308
+ 331: <span class="ruby-ivar">@request</span>
309
+ 332: <span class="ruby-keyword kw">end</span>
310
+ 333:
311
+ 334: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
312
+ 335: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
313
+ 336: <span class="ruby-ivar">@response</span>
314
+ 337: <span class="ruby-keyword kw">end</span>
315
+ 338:
316
+ 339: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>( <span class="ruby-identifier">e</span> ) <span class="ruby-comment cmt">#:nodoc:</span>
317
+ 340: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
318
+ 341: <span class="ruby-ivar">@response</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Response</span>.<span class="ruby-identifier">new</span>
319
+ 342: <span class="ruby-ivar">@request</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@env</span>)
320
+ 343:
321
+ 344: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
322
+ 345: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
323
+ 346: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
324
+ 347: <span class="ruby-comment cmt"># __run = true</span>
325
+ 348: <span class="ruby-comment cmt"># if f[:only]</span>
326
+ 349: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
327
+ 350: <span class="ruby-comment cmt"># end</span>
328
+ 351: <span class="ruby-comment cmt"># if f[:except]</span>
329
+ 352: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
330
+ 353: <span class="ruby-comment cmt"># end</span>
331
+ 354: <span class="ruby-comment cmt"># </span>
332
+ 355: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
333
+ 356: <span class="ruby-comment cmt"># puts &quot;call #{proc} for #{__k}&quot;</span>
334
+ 357: <span class="ruby-comment cmt"># end</span>
335
+ 358:
336
+ 359: <span class="ruby-comment cmt"># Check authz</span>
337
+ 360: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
338
+ 361: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
339
+ 362: <span class="ruby-identifier">authz_options</span> = <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>[<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>
340
+ 363: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
341
+ 364: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
342
+ 365:
343
+ 366: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span>, <span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
344
+ 367: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">&quot;^#{r.gsub(/\/$/, &quot;&quot;)}([/]{1}.*)?$&quot;</span>
345
+ 368: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">regexp</span>).<span class="ruby-identifier">match</span>( <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span> )
346
+ 369: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">size</span>
347
+ 370: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
348
+ 371: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
349
+ 372: <span class="ruby-keyword kw">end</span>
350
+ 373: <span class="ruby-keyword kw">end</span>
351
+ 374: <span class="ruby-keyword kw">end</span>
352
+ 375: <span class="ruby-keyword kw">end</span>
353
+ 376: <span class="ruby-keyword kw">end</span>
354
+ 377:
355
+ 378: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
356
+ 379: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
357
+ 380: <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:type</span>], <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:realm</span>], <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:realm</span>] ) {
358
+ 381: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
359
+ 382: }
360
+ 383: <span class="ruby-keyword kw">end</span>
361
+ 384:
362
+ 385: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
363
+ 386: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;GET&quot;</span>
364
+ 387: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
365
+ 388: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
366
+ 389: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
367
+ 390:
368
+ 391: <span class="ruby-identifier">aPath</span> = <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">&quot;/&quot;</span> )
369
+ 392: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
370
+ 393: <span class="ruby-identifier">xPath</span> = <span class="ruby-identifier">p</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">&quot;/&quot;</span> )
371
+ 394: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">aPath</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
372
+ 395: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
373
+ 396: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
374
+ 397: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">finalNArgs</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">finalNArgs</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">diffNArgs</span>
375
+ 398: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
376
+ 399: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
377
+ 400: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
378
+ 401: <span class="ruby-keyword kw">end</span>
379
+ 402: <span class="ruby-keyword kw">end</span>
380
+ 403:
381
+ 404: <span class="ruby-keyword kw">end</span>
382
+ 405:
383
+ 406: <span class="ruby-identifier">nargs</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">1</span>]
384
+ 407: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>][<span class="ruby-identifier">finalPath</span>] )
385
+ 408: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>( <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>).<span class="ruby-identifier">gsub</span>( <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-node">&quot;^#{finalPath}&quot;</span> ), <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span> ) )
386
+ 409: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
387
+ 410: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-node">&quot;Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'&quot;</span>
388
+ 411: <span class="ruby-keyword kw">else</span>
389
+ 412: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">x</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)<span class="ruby-operator">?</span><span class="ruby-keyword kw">nil</span><span class="ruby-operator">:</span><span class="ruby-identifier">x</span> }
390
+ 413: <span class="ruby-keyword kw">end</span>
391
+ 414:
392
+ 415: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">nargs</span>
393
+ 416: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
394
+ 417: <span class="ruby-keyword kw">end</span>
395
+ 418:
396
+ 419: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
397
+ 420: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
398
+ 421: <span class="ruby-identifier">_method</span> = <span class="ruby-identifier">params</span>.<span class="ruby-identifier">delete</span>( <span class="ruby-value str">&quot;_method&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-value str">&quot;post&quot;</span> }
399
+ 422: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span> )
400
+ 423: <span class="ruby-keyword kw">else</span>
401
+ 424: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
402
+ 425: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span> )
403
+ 426: <span class="ruby-keyword kw">end</span>
404
+ 427: }
405
+ 428: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_ary</span>)
406
+ 429: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[0]</span>
407
+ 430: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
408
+ 431: <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
409
+ 432: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
410
+ 433: <span class="ruby-keyword kw">end</span>
411
+ 434: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[2]</span>
412
+ 435: <span class="ruby-keyword kw">else</span>
413
+ 436: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
414
+ 437: <span class="ruby-keyword kw">end</span>
415
+ 438:
416
+ 439: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
417
+ 440: <span class="ruby-keyword kw">end</span>
418
+ 441:
419
+ 442: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
420
+ 443: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
421
+ 444: }
422
+ 445: <span class="ruby-keyword kw">end</span>
423
+ </pre>
424
+ </div>
425
+ </div>
426
+ </div>
427
+
428
+ <div id="method-M000009" class="method-detail">
429
+ <a name="M000009"></a>
430
+
431
+ <div class="method-heading">
432
+ <a href="#M000009" class="method-signature">
433
+ <span class="method-name">application</span><span class="method-args">( args = {} ) {|self| ...}</span>
434
+ </a>
435
+ </div>
436
+
437
+ <div class="method-description">
438
+ <p>
439
+ Return the Rack App.
440
+ </p>
441
+ <p>
442
+ Options : same has <a href="Capcode.html#M000010">Capcode.run</a>
443
+ </p>
444
+ <p><a class="source-toggle" href="#"
445
+ onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
446
+ <div class="method-source-code" id="M000009-source">
447
+ <pre>
448
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 512</span>
449
+ 512: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
450
+ 513: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
451
+ 514:
452
+ 515: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
453
+ 516: <span class="ruby-keyword kw">begin</span>
454
+ 517: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.public_methods(true).include?( '__urls__' )&quot;</span>
455
+ 518: <span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.__urls__&quot;</span>
456
+ 519: <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
457
+ 520: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">&quot;Route `#{current_route_path}' already define !&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@__ROUTES</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">current_route_path</span>)
458
+ 521: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>
459
+ 522: <span class="ruby-keyword kw">end</span>
460
+ 523: <span class="ruby-keyword kw">end</span>
461
+ 524: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
462
+ 525: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
463
+ 526: <span class="ruby-keyword kw">end</span>
464
+ 527: <span class="ruby-keyword kw">end</span>
465
+ 528:
466
+ 529: <span class="ruby-comment cmt"># Set Static directory</span>
467
+ 530: <span class="ruby-ivar">@@__STATIC_DIR</span> = (<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">chr</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;/&quot;</span>)<span class="ruby-operator">?</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>]<span class="ruby-operator">:</span><span class="ruby-value str">&quot;/&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
468
+ 531:
469
+ 532: <span class="ruby-comment cmt"># Initialize Rack App</span>
470
+ 533: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;** Map routes.&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
471
+ 534: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@@__ROUTES</span>)
472
+ 535: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Initialize static directory (#{conf[:static]})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
473
+ 536: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Static</span>.<span class="ruby-identifier">new</span>(
474
+ 537: <span class="ruby-identifier">app</span>,
475
+ 538: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-ivar">@@__STATIC_DIR</span>],
476
+ 539: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>])
477
+ 540: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
478
+ 541: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;** Initialize session&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
479
+ 542: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:session</span>] )
480
+ 543: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
481
+ 544: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
482
+ 545: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
483
+ 546: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ShowExceptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
484
+ 547: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
485
+ 548: <span class="ruby-comment cmt"># app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )</span>
486
+ 549:
487
+ 550: <span class="ruby-comment cmt"># Start database</span>
488
+ 551: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">&quot;db_connect&quot;</span>
489
+ 552: <span class="ruby-identifier">db_connect</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:db_config</span>], <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>] )
490
+ 553: <span class="ruby-keyword kw">end</span>
491
+ 554:
492
+ 555: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
493
+ 556: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
494
+ 557: <span class="ruby-keyword kw">end</span>
495
+ 558:
496
+ 559: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
497
+ 560: <span class="ruby-keyword kw">end</span>
498
+ </pre>
499
+ </div>
500
+ </div>
501
+ </div>
502
+
503
+ <div id="method-M000003" class="method-detail">
504
+ <a name="M000003"></a>
505
+
506
+ <div class="method-heading">
507
+ <a href="#M000003" class="method-signature">
508
+ <span class="method-name">env</span><span class="method-args">()</span>
509
+ </a>
510
+ </div>
511
+
512
+ <div class="method-description">
513
+ <p>
514
+ Hash containing all the environment variables
515
+ </p>
516
+ <p><a class="source-toggle" href="#"
517
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
518
+ <div class="method-source-code" id="M000003-source">
519
+ <pre>
520
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 320</span>
521
+ 320: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
522
+ 321: <span class="ruby-ivar">@env</span>
523
+ 322: <span class="ruby-keyword kw">end</span>
524
+ </pre>
525
+ </div>
526
+ </div>
527
+ </div>
528
+
529
+ <div id="method-M000008" class="method-detail">
530
+ <a name="M000008"></a>
531
+
532
+ <div class="method-heading">
533
+ <a href="#M000008" class="method-signature">
534
+ <span class="method-name">http_authentication</span><span class="method-args">( opts = {}, &amp;b )</span>
535
+ </a>
536
+ </div>
537
+
538
+ <div class="method-description">
539
+ <p>
540
+ Allow you to add and HTTP Authentication (Basic or Digest) to controllers
541
+ for or specific route
542
+ </p>
543
+ <p>
544
+ Options :
545
+ </p>
546
+ <ul>
547
+ <li><tt>:type</tt> : Authentication type (<tt>:basic</tt> or <tt>:digest</tt>)
548
+ - default : <tt>:basic</tt>
549
+
550
+ </li>
551
+ <li><tt>:realm</tt> : realm ;) - default : &quot;Capcode.app&quot;
552
+
553
+ </li>
554
+ <li><tt>:opaque</tt> : Your secret passphrase. You MUST set it if you use
555
+ Digest Auth - default : &quot;opaque&quot;
556
+
557
+ </li>
558
+ <li><tt>:routes</tt> : Routes - default : &quot;/&quot;
559
+
560
+ </li>
561
+ </ul>
562
+ <p>
563
+ The block must return a Hash of username =&gt; password like that :
564
+ </p>
565
+ <pre>
566
+ {
567
+ &quot;user1&quot; =&gt; &quot;pass1&quot;,
568
+ &quot;user2&quot; =&gt; &quot;pass2&quot;,
569
+ # ...
570
+ }
571
+ </pre>
572
+ <p><a class="source-toggle" href="#"
573
+ onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
574
+ <div class="method-source-code" id="M000008-source">
575
+ <pre>
576
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 470</span>
577
+ 470: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
578
+ 471: <span class="ruby-identifier">options</span> = {
579
+ 472: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:basic</span>,
580
+ 473: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;Capcode.app&quot;</span>,
581
+ 474: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;opaque&quot;</span>,
582
+ 475: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/&quot;</span>
583
+ 476: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
584
+ 477:
585
+ 478: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
586
+ 479:
587
+ 480: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
588
+ 481:
589
+ 482: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Array</span>
590
+ 483: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
591
+ 484: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
592
+ 485: <span class="ruby-keyword kw">end</span>
593
+ 486: <span class="ruby-keyword kw">else</span>
594
+ 487: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
595
+ 488: <span class="ruby-keyword kw">end</span>
596
+ 489: <span class="ruby-keyword kw">end</span>
597
+ </pre>
598
+ </div>
599
+ </div>
600
+ </div>
601
+
602
+ <div id="method-M000007" class="method-detail">
603
+ <a name="M000007"></a>
604
+
605
+ <div class="method-heading">
606
+ <a href="#M000007" class="method-signature">
607
+ <span class="method-name">map</span><span class="method-args">( route ) {|| ...}</span>
608
+ </a>
609
+ </div>
610
+
611
+ <div class="method-description">
612
+ <p>
613
+ This method help you to <a href="Capcode.html#M000007">map</a> and URL to a
614
+ Rack or What you want Helper
615
+ </p>
616
+ <pre>
617
+ Capcode.map( &quot;/file&quot; ) do
618
+ Rack::File.new( &quot;.&quot; )
619
+ end
620
+ </pre>
621
+ <p><a class="source-toggle" href="#"
622
+ onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
623
+ <div class="method-source-code" id="M000007-source">
624
+ <pre>
625
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 452</span>
626
+ 452: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">route</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
627
+ 453: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">route</span>] = <span class="ruby-keyword kw">yield</span>
628
+ 454: <span class="ruby-keyword kw">end</span>
629
+ </pre>
630
+ </div>
631
+ </div>
632
+ </div>
633
+
634
+ <div id="method-M000002" class="method-detail">
635
+ <a name="M000002"></a>
636
+
637
+ <div class="method-heading">
638
+ <a href="#M000002" class="method-signature">
639
+ <span class="method-name">params</span><span class="method-args">()</span>
640
+ </a>
641
+ </div>
642
+
643
+ <div class="method-description">
644
+ <p>
645
+ Hash containing all the <a href="Capcode.html#M000005">request</a>
646
+ parameters (GET or POST)
647
+ </p>
648
+ <p><a class="source-toggle" href="#"
649
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
650
+ <div class="method-source-code" id="M000002-source">
651
+ <pre>
652
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 315</span>
653
+ 315: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
654
+ 316: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
655
+ 317: <span class="ruby-keyword kw">end</span>
656
+ </pre>
657
+ </div>
658
+ </div>
659
+ </div>
660
+
661
+ <div id="method-M000005" class="method-detail">
662
+ <a name="M000005"></a>
663
+
664
+ <div class="method-heading">
665
+ <a href="#M000005" class="method-signature">
666
+ <span class="method-name">request</span><span class="method-args">()</span>
667
+ </a>
668
+ </div>
669
+
670
+ <div class="method-description">
671
+ <p>
672
+ Return the Rack::Request object
673
+ </p>
674
+ <p><a class="source-toggle" href="#"
675
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
676
+ <div class="method-source-code" id="M000005-source">
677
+ <pre>
678
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 330</span>
679
+ 330: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
680
+ 331: <span class="ruby-ivar">@request</span>
681
+ 332: <span class="ruby-keyword kw">end</span>
682
+ </pre>
683
+ </div>
684
+ </div>
685
+ </div>
686
+
687
+ <div id="method-M000006" class="method-detail">
688
+ <a name="M000006"></a>
689
+
690
+ <div class="method-heading">
691
+ <a href="#M000006" class="method-signature">
692
+ <span class="method-name">response</span><span class="method-args">()</span>
693
+ </a>
694
+ </div>
695
+
696
+ <div class="method-description">
697
+ <p>
698
+ Return the Rack::Response object
699
+ </p>
700
+ <p><a class="source-toggle" href="#"
701
+ onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
702
+ <div class="method-source-code" id="M000006-source">
703
+ <pre>
704
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 335</span>
705
+ 335: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
706
+ 336: <span class="ruby-ivar">@response</span>
707
+ 337: <span class="ruby-keyword kw">end</span>
708
+ </pre>
709
+ </div>
710
+ </div>
711
+ </div>
712
+
713
+ <div id="method-M000010" class="method-detail">
714
+ <a name="M000010"></a>
715
+
716
+ <div class="method-heading">
717
+ <a href="#M000010" class="method-signature">
718
+ <span class="method-name">run</span><span class="method-args">( args = {} ) {|self| ...}</span>
719
+ </a>
720
+ </div>
721
+
722
+ <div class="method-description">
723
+ <p>
724
+ Start your <a href="Capcode.html#M000009">application</a>.
725
+ </p>
726
+ <p>
727
+ Options :
728
+ </p>
729
+ <ul>
730
+ <li><tt>:port</tt> = Listen port (default: 3000)
731
+
732
+ </li>
733
+ <li><tt>:host</tt> = Listen host (default: 0.0.0.0)
734
+
735
+ </li>
736
+ <li><tt>:server</tt> = Server type (webrick or mongrel)
737
+
738
+ </li>
739
+ <li><tt>:log</tt> = Output logfile (default: STDOUT)
740
+
741
+ </li>
742
+ <li><tt>:<a href="Capcode.html#M000004">session</a></tt> = Session parameters.
743
+ See Rack::Session for more informations
744
+
745
+ </li>
746
+ <li><tt>:pid</tt> = PID file (default: $0.pid)
747
+
748
+ </li>
749
+ <li><tt>:daemonize</tt> = Daemonize <a
750
+ href="Capcode.html#M000009">application</a> (default: false)
751
+
752
+ </li>
753
+ <li><tt>:db_config</tt> = database configuration file (default: database.yml)
754
+
755
+ </li>
756
+ <li><tt>:static</tt> = Static directory (default: none &#8212; relative to the
757
+ working directory)
758
+
759
+ </li>
760
+ <li><tt>:root</tt> = Root directory (default: directory of the main.rb) &#8212;
761
+ This is also the working directory !
762
+
763
+ </li>
764
+ <li><tt>:verbose</tt> = <a href="Capcode.html#M000010">run</a> in verbose mode
765
+
766
+ </li>
767
+ <li><tt>:auth</tt> = HTTP Basic Authentication options
768
+
769
+ </li>
770
+ </ul>
771
+ <p><a class="source-toggle" href="#"
772
+ onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
773
+ <div class="method-source-code" id="M000010-source">
774
+ <pre>
775
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 577</span>
776
+ 577: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
777
+ 578: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
778
+ 579:
779
+ 580: <span class="ruby-comment cmt"># Parse options</span>
780
+ 581: <span class="ruby-identifier">opts</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
781
+ 582: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
782
+ 583: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
783
+ 584: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
784
+ 585:
785
+ 586: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-C&quot;</span>, <span class="ruby-value str">&quot;--console&quot;</span>, <span class="ruby-value str">&quot;Run in console mode with IRB (default: false)&quot;</span> ) {
786
+ 587: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>] = <span class="ruby-keyword kw">true</span>
787
+ 588: }
788
+ 589: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-h&quot;</span>, <span class="ruby-value str">&quot;--host HOSTNAME&quot;</span>, <span class="ruby-node">&quot;Host for web server to bind to (default: #{conf[:host]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
789
+ 590: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
790
+ 591: }
791
+ 592: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-p&quot;</span>, <span class="ruby-value str">&quot;--port NUM&quot;</span>, <span class="ruby-node">&quot;Port for web server (default: #{conf[:port]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
792
+ 593: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">p</span>
793
+ 594: }
794
+ 595: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-d&quot;</span>, <span class="ruby-value str">&quot;--daemonize [true|false]&quot;</span>, <span class="ruby-node">&quot;Daemonize (default: #{conf[:daemonize]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
795
+ 596: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span>
796
+ 597: }
797
+ 598: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-r&quot;</span>, <span class="ruby-value str">&quot;--root PATH&quot;</span>, <span class="ruby-node">&quot;Working directory (default: #{conf[:root]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
798
+ 599: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] = <span class="ruby-identifier">w</span>
799
+ 600: }
800
+ 601: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-s&quot;</span>, <span class="ruby-value str">&quot;--static PATH&quot;</span>, <span class="ruby-node">&quot;Static directory -- relative to the root directory (default: #{conf[:static]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
801
+ 602: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] = <span class="ruby-identifier">r</span>
802
+ 603: }
803
+ 604:
804
+ 605: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
805
+ 606: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
806
+ 607:
807
+ 608: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-?&quot;</span>, <span class="ruby-value str">&quot;--help&quot;</span>, <span class="ruby-value str">&quot;Show this message&quot;</span>) <span class="ruby-keyword kw">do</span>
808
+ 609: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
809
+ 610: <span class="ruby-identifier">exit</span>
810
+ 611: <span class="ruby-keyword kw">end</span>
811
+ 612: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-v&quot;</span>, <span class="ruby-value str">&quot;--version&quot;</span>, <span class="ruby-value str">&quot;Show versions&quot;</span>) <span class="ruby-keyword kw">do</span>
812
+ 613: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
813
+ 614: <span class="ruby-identifier">exit</span>
814
+ 615: <span class="ruby-keyword kw">end</span>
815
+ 616: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</span>( <span class="ruby-value str">&quot;-V&quot;</span>, <span class="ruby-value str">&quot;--verbose&quot;</span>, <span class="ruby-value str">&quot;Run in verbose mode&quot;</span> ) <span class="ruby-keyword kw">do</span>
816
+ 617: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>] = <span class="ruby-keyword kw">true</span>
817
+ 618: <span class="ruby-keyword kw">end</span>
818
+ 619: <span class="ruby-keyword kw">end</span>
819
+ 620:
820
+ 621: <span class="ruby-keyword kw">begin</span>
821
+ 622: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
822
+ 623: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">ParseError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
823
+ 624: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
824
+ 625: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
825
+ 626: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
826
+ 627: <span class="ruby-keyword kw">end</span>
827
+ 628:
828
+ 629: <span class="ruby-comment cmt"># Run in the Working directory</span>
829
+ 630: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Go on root directory (#{File.expand_path(conf[:root])})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
830
+ 631: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] ) <span class="ruby-keyword kw">do</span>
831
+ 632:
832
+ 633: <span class="ruby-comment cmt"># Check that mongrel exists </span>
833
+ 634: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
834
+ 635: <span class="ruby-keyword kw">begin</span>
835
+ 636: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
836
+ 637: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;mongrel&quot;</span>
837
+ 638: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
838
+ 639: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
839
+ 640: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;webrick&quot;</span>
840
+ 641: <span class="ruby-keyword kw">end</span>
841
+ 642: <span class="ruby-keyword kw">end</span>
842
+ 643:
843
+ 644: <span class="ruby-comment cmt"># From rackup !!!</span>
844
+ 645: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
845
+ 646: <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/java/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">RUBY_PLATFORM</span>).<span class="ruby-identifier">nil?</span>
846
+ 647: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value str">&quot;1.9&quot;</span>
847
+ 648: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
848
+ 649: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
849
+ 650: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
850
+ 651: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
851
+ 652: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
852
+ 653: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
853
+ 654: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
854
+ 655: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
855
+ 656: <span class="ruby-keyword kw">else</span>
856
+ 657: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
857
+ 658: <span class="ruby-keyword kw">end</span>
858
+ 659: <span class="ruby-keyword kw">else</span>
859
+ 660: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
860
+ 661: <span class="ruby-keyword kw">end</span>
861
+ 662:
862
+ 663: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>], <span class="ruby-value str">'w'</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;#{Process.pid}&quot;</span>) }
863
+ 664: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) }
864
+ 665: <span class="ruby-keyword kw">end</span>
865
+ 666:
866
+ 667: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
867
+ 668: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
868
+ 669: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
869
+ 670: <span class="ruby-keyword kw">else</span>
870
+ 671: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>)
871
+ 672: <span class="ruby-keyword kw">end</span>
872
+ 673: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>]) )
873
+ 674:
874
+ 675: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>]
875
+ 676: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
876
+ 677: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
877
+ 678: <span class="ruby-identifier">exit</span>
878
+ 679: <span class="ruby-keyword kw">end</span>
879
+ 680:
880
+ 681: <span class="ruby-comment cmt"># Start server</span>
881
+ 682: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
882
+ 683: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
883
+ 684: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{conf[:host]}:#{conf[:port]}&quot;</span>
884
+ 685: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
885
+ 686: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
886
+ 687: }
887
+ 688: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
888
+ 689: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{conf[:host]}:#{conf[:port]}&quot;</span>
889
+ 690: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">WEBrick</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
890
+ 691: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
891
+ 692: }
892
+ 693: <span class="ruby-keyword kw">end</span>
893
+ 694: <span class="ruby-keyword kw">end</span>
894
+ 695: <span class="ruby-keyword kw">end</span>
895
+ </pre>
896
+ </div>
897
+ </div>
898
+ </div>
899
+
900
+ <div id="method-M000004" class="method-detail">
901
+ <a name="M000004"></a>
902
+
903
+ <div class="method-heading">
904
+ <a href="#M000004" class="method-signature">
905
+ <span class="method-name">session</span><span class="method-args">()</span>
906
+ </a>
907
+ </div>
908
+
909
+ <div class="method-description">
910
+ <p>
911
+ Session hash
912
+ </p>
913
+ <p><a class="source-toggle" href="#"
914
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
915
+ <div class="method-source-code" id="M000004-source">
916
+ <pre>
917
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 325</span>
918
+ 325: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
919
+ 326: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
920
+ 327: <span class="ruby-keyword kw">end</span>
921
+ </pre>
922
+ </div>
923
+ </div>
924
+ </div>
925
+
926
+
927
+ </div>
928
+
929
+
930
+ </div>
931
+
932
+
933
+ <div id="validator-badges">
934
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
935
+ </div>
936
+
937
+ </body>
938
+ </html>