Capcode 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = Capcode
2
2
 
3
- Copyright (C) 2009 Gregoire Lejeune
3
+ Copyright (C) 2009, 2010 Gregoire Lejeune
4
4
 
5
5
  * home : http://capcode.rubyforge.org
6
6
  * doc : http://rdoc.info/projects/glejeune/Capcode
@@ -12,6 +12,11 @@ Capcode is a web microframework
12
12
 
13
13
  == FEATURES/PROBLEMS:
14
14
 
15
+ === 0.9.2
16
+ * Remove JSON dependency
17
+ * Add the "HTTP code" renderer, so you can now use something like this : render 200 => "OK", :server => "Capcode", ...
18
+ * Reintroduce before_filter. {See example filter.rb}[http://github.com/glejeune/Capcode/tree/master/examples/filter.rb].
19
+
15
20
  === 0.9.1
16
21
  * You don't need to require the renderers. This will be done by Capcode at use time.
17
22
  * Major bug correction for jRuby
@@ -20,7 +25,7 @@ Capcode is a web microframework
20
25
 
21
26
  * <b>IMPORTANT</b>
22
27
  * THIS VERSION IS A MAJOR ENHANCEMENT : YOU MUST UNINSTALL ALL PREVIOUS VERSIONS !!!
23
- gem uninstall Capode --version '< 0.9.0'
28
+ gem uninstall Capode --version '< 0.9.0'
24
29
  * Renderers and database accessors have been extracted and are now in the {plugins repository}[http://github.com/glejeune/Capcode.more]. Each plugin is a gem that's can be installed separately.
25
30
  * <b>Important, but less!</b>
26
31
  * Add {Coffee-Script}[http://jashkenas.github.com/coffee-script/] renderer
@@ -66,6 +66,10 @@
66
66
  <a href="../files/lib/capcode/configuration_rb.html">
67
67
  lib/capcode/configuration.rb
68
68
  </a>
69
+ <br />
70
+ <a href="../files/lib/capcode/filters_rb.html">
71
+ lib/capcode/filters.rb
72
+ </a>
69
73
  <br />
70
74
  <a href="../files/lib/capcode/render/text_rb.html">
71
75
  lib/capcode/render/text.rb
@@ -98,6 +102,7 @@
98
102
  <div class="name-list">
99
103
  <a href="#M000001">Route</a>&nbsp;&nbsp;
100
104
  <a href="#M000010">application</a>&nbsp;&nbsp;
105
+ <a href="#M000013">before_filter</a>&nbsp;&nbsp;
101
106
  <a href="#M000003">env</a>&nbsp;&nbsp;
102
107
  <a href="#M000009">http_authentication</a>&nbsp;&nbsp;
103
108
  <a href="#M000007">map</a>&nbsp;&nbsp;
@@ -202,169 +207,175 @@ If the regexp in the route does not match, all arguments will be
202
207
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
203
208
  <div class="method-source-code" id="M000001-source">
204
209
  <pre>
205
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 316</span>
206
- 316: <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>
207
- 317: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
208
- 318: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
209
- 319: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/</span>
210
- 320: <span class="ruby-comment cmt"># # =&gt; [ {'/hello/world' =&gt; '([^\/]*)/id(\d*)', '/hello' =&gt; '(.*)'}, </span>
211
- 321: <span class="ruby-comment cmt"># 2, </span>
212
- 322: <span class="ruby-comment cmt"># &lt;Capcode::Klass&gt;, </span>
213
- 323: <span class="ruby-comment cmt"># {:agent =&gt; /Songbird (\d\.\d)[\d\/]*?/} ]</span>
214
- 324: <span class="ruby-identifier">hash_of_routes</span> = {}
215
- 325: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
216
- 326: <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>
217
- 327: <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>
218
- 328: <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> )
219
- 329: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
220
- 330: <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>)
221
- 331: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
222
- 332: <span class="ruby-keyword kw">else</span>
223
- 333: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
224
- 334: <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>
225
- 335: <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>)
226
- 336: <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>]
227
- 337: <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>
228
- 338: <span class="ruby-keyword kw">end</span>
229
- 339: <span class="ruby-keyword kw">else</span>
230
- 340: <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>
231
- 341: <span class="ruby-keyword kw">end</span>
232
- 342: <span class="ruby-keyword kw">end</span>
233
- 343: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
234
- 344: }
235
- 345:
236
- 346: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
237
- 347: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
238
- 348: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
239
- 349: <span class="ruby-keyword kw">end</span>
240
- 350:
241
- 351: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
242
- 352: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
243
- 353: <span class="ruby-ivar">@env</span>
244
- 354: <span class="ruby-keyword kw">end</span>
245
- 355:
246
- 356: <span class="ruby-comment cmt"># Session hash</span>
247
- 357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
248
- 358: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
249
- 359: <span class="ruby-keyword kw">end</span>
250
- 360:
251
- 361: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
252
- 362: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
253
- 363: <span class="ruby-ivar">@request</span>
254
- 364: <span class="ruby-keyword kw">end</span>
255
- 365:
256
- 366: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
257
- 367: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
258
- 368: <span class="ruby-ivar">@response</span>
259
- 369: <span class="ruby-keyword kw">end</span>
260
- 370:
261
- 371: <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>
262
- 372: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
263
- 373: <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>
264
- 374: <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>)
265
- 375:
266
- 376: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
267
- 377: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
268
- 378: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
269
- 379: <span class="ruby-comment cmt"># __run = true</span>
270
- 380: <span class="ruby-comment cmt"># if f[:only]</span>
271
- 381: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
272
- 382: <span class="ruby-comment cmt"># end</span>
273
- 383: <span class="ruby-comment cmt"># if f[:except]</span>
274
- 384: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
275
- 385: <span class="ruby-comment cmt"># end</span>
276
- 386: <span class="ruby-comment cmt"># </span>
277
- 387: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
278
- 388: <span class="ruby-comment cmt"># puts &quot;call #{proc} for #{__k}&quot;</span>
279
- 389: <span class="ruby-comment cmt"># end</span>
280
- 390:
281
- 391: <span class="ruby-comment cmt"># Check authz</span>
282
- 392: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
283
- 393: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span> <span class="ruby-keyword kw">and</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>
284
- 394: <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>
285
- 395: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
286
- 396: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
287
- 397:
288
- 398: <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>
289
- 399: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">&quot;^#{r.gsub(/\/$/, &quot;&quot;)}([/]{1}.*)?$&quot;</span>
290
- 400: <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> )
291
- 401: <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>
292
- 402: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
293
- 403: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
294
- 404: <span class="ruby-keyword kw">end</span>
295
- 405: <span class="ruby-keyword kw">end</span>
296
- 406: <span class="ruby-keyword kw">end</span>
297
- 407: <span class="ruby-keyword kw">end</span>
298
- 408: <span class="ruby-keyword kw">end</span>
299
- 409:
300
- 410: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
301
- 411: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
302
- 412: <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>] ) {
303
- 413: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
304
- 414: }
305
- 415: <span class="ruby-keyword kw">end</span>
306
- 416:
307
- 417: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
308
- 418: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
309
- 419: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
310
- 420:
311
- 421: <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> )
312
- 422: <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>
313
- 423: <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> )
314
- 424: <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>
315
- 425: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
316
- 426: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
317
- 427: <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>
318
- 428: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
319
- 429: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
320
- 430: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
321
- 431: <span class="ruby-keyword kw">end</span>
322
- 432: <span class="ruby-keyword kw">end</span>
323
- 433:
324
- 434: <span class="ruby-keyword kw">end</span>
325
- 435:
326
- 436: <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>]
327
- 437: <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>] )
328
- 438: <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> ) )
329
- 439: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
330
- 440: <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>
331
- 441: <span class="ruby-keyword kw">else</span>
332
- 442: <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> }
333
- 443: <span class="ruby-keyword kw">end</span>
334
- 444:
335
- 445: <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>
336
- 446: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
337
- 447: <span class="ruby-keyword kw">end</span>
338
- 448:
339
- 449: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
340
- 450: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;GET&quot;</span>
341
- 451: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
342
- 452: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
343
- 453: <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> }
344
- 454: <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>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
345
- 455: <span class="ruby-keyword kw">else</span>
346
- 456: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
347
- 457: <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>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
348
- 458: <span class="ruby-keyword kw">end</span>
349
- 459: }
350
- 460: <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>)
351
- 461: <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>
352
- 462: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
353
- 463: <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>
354
- 464: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
210
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 334</span>
211
+ 334: <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>
212
+ 335: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
213
+ 336: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
214
+ 337: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/</span>
215
+ 338: <span class="ruby-comment cmt"># # =&gt; [ {'/hello/world' =&gt; '([^\/]*)/id(\d*)', '/hello' =&gt; '(.*)'}, </span>
216
+ 339: <span class="ruby-comment cmt"># 2, </span>
217
+ 340: <span class="ruby-comment cmt"># &lt;Capcode::Klass&gt;, </span>
218
+ 341: <span class="ruby-comment cmt"># {:agent =&gt; /Songbird (\d\.\d)[\d\/]*?/} ]</span>
219
+ 342: <span class="ruby-identifier">hash_of_routes</span> = {}
220
+ 343: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
221
+ 344: <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>
222
+ 345: <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>
223
+ 346: <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> )
224
+ 347: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
225
+ 348: <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>)
226
+ 349: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
227
+ 350: <span class="ruby-keyword kw">else</span>
228
+ 351: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
229
+ 352: <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>
230
+ 353: <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>)
231
+ 354: <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>]
232
+ 355: <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>
233
+ 356: <span class="ruby-keyword kw">end</span>
234
+ 357: <span class="ruby-keyword kw">else</span>
235
+ 358: <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>
236
+ 359: <span class="ruby-keyword kw">end</span>
237
+ 360: <span class="ruby-keyword kw">end</span>
238
+ 361: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
239
+ 362: }
240
+ 363:
241
+ 364: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
242
+ 365: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
243
+ 366: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
244
+ 367: <span class="ruby-keyword kw">end</span>
245
+ 368:
246
+ 369: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
247
+ 370: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
248
+ 371: <span class="ruby-ivar">@env</span>
249
+ 372: <span class="ruby-keyword kw">end</span>
250
+ 373:
251
+ 374: <span class="ruby-comment cmt"># Session hash</span>
252
+ 375: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
253
+ 376: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
254
+ 377: <span class="ruby-keyword kw">end</span>
255
+ 378:
256
+ 379: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
257
+ 380: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
258
+ 381: <span class="ruby-ivar">@request</span>
259
+ 382: <span class="ruby-keyword kw">end</span>
260
+ 383:
261
+ 384: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
262
+ 385: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
263
+ 386: <span class="ruby-ivar">@response</span>
264
+ 387: <span class="ruby-keyword kw">end</span>
265
+ 388:
266
+ 389: <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>
267
+ 390: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
268
+ 391: <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>
269
+ 392: <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>)
270
+ 393:
271
+ 394: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
272
+ 395: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
273
+ 396: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
274
+ 397: <span class="ruby-comment cmt"># __run = true</span>
275
+ 398: <span class="ruby-comment cmt"># if f[:only]</span>
276
+ 399: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
277
+ 400: <span class="ruby-comment cmt"># end</span>
278
+ 401: <span class="ruby-comment cmt"># if f[:except]</span>
279
+ 402: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
280
+ 403: <span class="ruby-comment cmt"># end</span>
281
+ 404: <span class="ruby-comment cmt"># </span>
282
+ 405: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
283
+ 406: <span class="ruby-comment cmt"># puts &quot;call #{proc} for #{__k}&quot;</span>
284
+ 407: <span class="ruby-comment cmt"># end</span>
285
+ 408:
286
+ 409: <span class="ruby-comment cmt"># Check authz</span>
287
+ 410: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
288
+ 411: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span> <span class="ruby-keyword kw">and</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>
289
+ 412: <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>
290
+ 413: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
291
+ 414: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
292
+ 415:
293
+ 416: <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>
294
+ 417: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">&quot;^#{r.gsub(/\/$/, &quot;&quot;)}([/]{1}.*)?$&quot;</span>
295
+ 418: <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> )
296
+ 419: <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>
297
+ 420: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
298
+ 421: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
299
+ 422: <span class="ruby-keyword kw">end</span>
300
+ 423: <span class="ruby-keyword kw">end</span>
301
+ 424: <span class="ruby-keyword kw">end</span>
302
+ 425: <span class="ruby-keyword kw">end</span>
303
+ 426: <span class="ruby-keyword kw">end</span>
304
+ 427:
305
+ 428: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
306
+ 429: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
307
+ 430: <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>] ) {
308
+ 431: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
309
+ 432: }
310
+ 433: <span class="ruby-keyword kw">end</span>
311
+ 434:
312
+ 435: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
313
+ 436: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
314
+ 437: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
315
+ 438:
316
+ 439: <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> )
317
+ 440: <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>
318
+ 441: <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> )
319
+ 442: <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>
320
+ 443: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
321
+ 444: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
322
+ 445: <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>
323
+ 446: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
324
+ 447: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
325
+ 448: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
326
+ 449: <span class="ruby-keyword kw">end</span>
327
+ 450: <span class="ruby-keyword kw">end</span>
328
+ 451:
329
+ 452: <span class="ruby-keyword kw">end</span>
330
+ 453:
331
+ 454: <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>]
332
+ 455: <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>] )
333
+ 456: <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> ) )
334
+ 457: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
335
+ 458: <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>
336
+ 459: <span class="ruby-keyword kw">else</span>
337
+ 460: <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> }
338
+ 461: <span class="ruby-keyword kw">end</span>
339
+ 462:
340
+ 463: <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>
341
+ 464: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
355
342
  465: <span class="ruby-keyword kw">end</span>
356
- 466: <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>
357
- 467: <span class="ruby-keyword kw">else</span>
358
- 468: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
359
- 469: <span class="ruby-keyword kw">end</span>
360
- 470:
361
- 471: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
362
- 472: <span class="ruby-keyword kw">end</span>
363
- 473:
364
- 474: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
365
- 475: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
366
- 476: }
367
- 477: <span class="ruby-keyword kw">end</span>
343
+ 466:
344
+ 467: <span class="ruby-identifier">filter_output</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Filter</span>.<span class="ruby-identifier">execute</span>( <span class="ruby-keyword kw">self</span> )
345
+ 468:
346
+ 469: <span class="ruby-keyword kw">if</span>( <span class="ruby-identifier">filter_output</span>.<span class="ruby-identifier">nil?</span> )
347
+ 470: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
348
+ 471: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;GET&quot;</span>
349
+ 472: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
350
+ 473: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
351
+ 474: <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> }
352
+ 475: <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>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
353
+ 476: <span class="ruby-keyword kw">else</span>
354
+ 477: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
355
+ 478: <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>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
356
+ 479: <span class="ruby-keyword kw">end</span>
357
+ 480: <span class="ruby-keyword kw">else</span>
358
+ 481: <span class="ruby-identifier">filter_output</span>
359
+ 482: <span class="ruby-keyword kw">end</span>
360
+ 483: }
361
+ 484: <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>)
362
+ 485: <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>
363
+ 486: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
364
+ 487: <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>
365
+ 488: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
366
+ 489: <span class="ruby-keyword kw">end</span>
367
+ 490: <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>
368
+ 491: <span class="ruby-keyword kw">else</span>
369
+ 492: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
370
+ 493: <span class="ruby-keyword kw">end</span>
371
+ 494:
372
+ 495: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
373
+ 496: <span class="ruby-keyword kw">end</span>
374
+ 497:
375
+ 498: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
376
+ 499: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
377
+ 500: }
378
+ 501: <span class="ruby-keyword kw">end</span>
368
379
  </pre>
369
380
  </div>
370
381
  </div>
@@ -385,7 +396,7 @@ Return the Rack App.
385
396
  </p>
386
397
  <p>
387
398
  Options : see <a
388
- href="Capcode/Configuration.html#M000022">Capcode::Configuration.set</a>
399
+ href="Capcode/Configuration.html#M000023">Capcode::Configuration.set</a>
389
400
  </p>
390
401
  <p>
391
402
  Options <a href="Capcode.html#M000012">set</a> here replace the ones <a
@@ -395,71 +406,112 @@ href="Capcode.html#M000012">set</a> globally
395
406
  onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
396
407
  <div class="method-source-code" id="M000010-source">
397
408
  <pre>
398
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 546</span>
399
- 546: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
400
- 547: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
401
- 548:
402
- 549: <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>
403
- 550: <span class="ruby-keyword kw">begin</span>
404
- 551: <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>
405
- 552: <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>
406
- 553: <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>
407
- 554: <span class="ruby-comment cmt">#raise Capcode::RouteError, &quot;Route `#{current_route_path}' already define !&quot;, caller if @@__ROUTES.keys.include?(current_route_path)</span>
408
- 555: <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-constant">Capcode</span>.<span class="ruby-identifier">routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">current_route_path</span>)
409
- 556: <span class="ruby-comment cmt">#@@__ROUTES[current_route_path] = klass.new</span>
410
- 557: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>
411
- 558: <span class="ruby-keyword kw">end</span>
412
- 559: <span class="ruby-keyword kw">end</span>
413
- 560: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
414
- 561: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
415
- 562: <span class="ruby-keyword kw">end</span>
416
- 563: <span class="ruby-keyword kw">end</span>
417
- 564:
418
- 565: <span class="ruby-comment cmt"># Set Static directory</span>
419
- 566: <span class="ruby-comment cmt">#@@__STATIC_DIR = (conf[:static][0].chr == &quot;/&quot;)?conf[:static]:&quot;/&quot;+conf[:static] unless conf[:static].nil?</span>
420
- 567: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span> = (<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>).<span class="ruby-identifier">nil?</span>
421
- 568:
422
- 569: <span class="ruby-comment cmt"># Initialize Rack App</span>
423
- 570: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
424
- 571: <span class="ruby-comment cmt">#app = Rack::URLMap.new(@@__ROUTES)</span>
425
- 572: <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-constant">Capcode</span>.<span class="ruby-identifier">routes</span>)
426
- 573: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Initialize static directory (#{Capcode::Configuration.get(:static)})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
427
- 574: <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>(
428
- 575: <span class="ruby-identifier">app</span>,
429
- 576: <span class="ruby-comment cmt">#:urls =&gt; [@@__STATIC_DIR], </span>
430
- 577: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
431
- 578: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>))
432
- 579: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>).<span class="ruby-identifier">nil?</span>
433
- 580: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
434
- 581: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:session</span>) )
435
- 582: <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>)
436
- 583: <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>)
437
- 584: <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>)
438
- 585: <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>)
439
- 586: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
440
- 587: <span class="ruby-comment cmt"># app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )</span>
409
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 570</span>
410
+ 570: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
411
+ 571: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
412
+ 572:
413
+ 573: <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>
414
+ 574: <span class="ruby-keyword kw">begin</span>
415
+ 575: <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>
416
+ 576: <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>
417
+ 577: <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>
418
+ 578: <span class="ruby-comment cmt">#raise Capcode::RouteError, &quot;Route `#{current_route_path}' already define !&quot;, caller if @@__ROUTES.keys.include?(current_route_path)</span>
419
+ 579: <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-constant">Capcode</span>.<span class="ruby-identifier">routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">current_route_path</span>)
420
+ 580: <span class="ruby-comment cmt">#@@__ROUTES[current_route_path] = klass.new</span>
421
+ 581: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>
422
+ 582: <span class="ruby-keyword kw">end</span>
423
+ 583: <span class="ruby-keyword kw">end</span>
424
+ 584: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
425
+ 585: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
426
+ 586: <span class="ruby-keyword kw">end</span>
427
+ 587: <span class="ruby-keyword kw">end</span>
441
428
  588:
442
- 589: <span class="ruby-identifier">middlewares</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mw</span><span class="ruby-operator">|</span>
443
- 590: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
444
- 591: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Load middleware #{middleware}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
445
- 592: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
446
- 593: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
447
- 594: <span class="ruby-keyword kw">else</span>
448
- 595: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
449
- 596: <span class="ruby-keyword kw">end</span>
450
- 597: <span class="ruby-keyword kw">end</span>
451
- 598:
452
- 599: <span class="ruby-comment cmt"># Start database</span>
453
- 600: <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>
454
- 601: <span class="ruby-identifier">db_connect</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:db_config</span>), <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>) )
455
- 602: <span class="ruby-keyword kw">end</span>
456
- 603:
457
- 604: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
458
- 605: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
459
- 606: <span class="ruby-keyword kw">end</span>
460
- 607:
461
- 608: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
462
- 609: <span class="ruby-keyword kw">end</span>
429
+ 589: <span class="ruby-comment cmt"># Set Static directory</span>
430
+ 590: <span class="ruby-comment cmt">#@@__STATIC_DIR = (conf[:static][0].chr == &quot;/&quot;)?conf[:static]:&quot;/&quot;+conf[:static] unless conf[:static].nil?</span>
431
+ 591: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span> = (<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>).<span class="ruby-identifier">nil?</span>
432
+ 592:
433
+ 593: <span class="ruby-comment cmt"># Initialize Rack App</span>
434
+ 594: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
435
+ 595: <span class="ruby-comment cmt">#app = Rack::URLMap.new(@@__ROUTES)</span>
436
+ 596: <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-constant">Capcode</span>.<span class="ruby-identifier">routes</span>)
437
+ 597: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Initialize static directory (#{Capcode::Configuration.get(:static)})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
438
+ 598: <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>(
439
+ 599: <span class="ruby-identifier">app</span>,
440
+ 600: <span class="ruby-comment cmt">#:urls =&gt; [@@__STATIC_DIR], </span>
441
+ 601: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
442
+ 602: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>))
443
+ 603: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>).<span class="ruby-identifier">nil?</span>
444
+ 604: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
445
+ 605: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:session</span>) )
446
+ 606: <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>)
447
+ 607: <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>)
448
+ 608: <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>)
449
+ 609: <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>)
450
+ 610: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
451
+ 611: <span class="ruby-comment cmt"># app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )</span>
452
+ 612:
453
+ 613: <span class="ruby-identifier">middlewares</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mw</span><span class="ruby-operator">|</span>
454
+ 614: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
455
+ 615: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Load middleware #{middleware}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
456
+ 616: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
457
+ 617: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
458
+ 618: <span class="ruby-keyword kw">else</span>
459
+ 619: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
460
+ 620: <span class="ruby-keyword kw">end</span>
461
+ 621: <span class="ruby-keyword kw">end</span>
462
+ 622:
463
+ 623: <span class="ruby-comment cmt"># Start database</span>
464
+ 624: <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>
465
+ 625: <span class="ruby-identifier">db_connect</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:db_config</span>), <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>) )
466
+ 626: <span class="ruby-keyword kw">end</span>
467
+ 627:
468
+ 628: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
469
+ 629: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
470
+ 630: <span class="ruby-keyword kw">end</span>
471
+ 631:
472
+ 632: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
473
+ 633: <span class="ruby-keyword kw">end</span>
474
+ </pre>
475
+ </div>
476
+ </div>
477
+ </div>
478
+
479
+ <div id="method-M000013" class="method-detail">
480
+ <a name="M000013"></a>
481
+
482
+ <div class="method-heading">
483
+ <a href="#M000013" class="method-signature">
484
+ <span class="method-name">before_filter</span><span class="method-args">( action, opts = {} )</span>
485
+ </a>
486
+ </div>
487
+
488
+ <div class="method-description">
489
+ <p>
490
+ Add a before filter :
491
+ </p>
492
+ <pre>
493
+ module Capcode
494
+ before_filter :my_global_action
495
+ before_filter :need_login, :except =&gt; [:Login]
496
+ before_filter :check_mail, :only =&gt; [:MailBox]
497
+ # ...
498
+ end
499
+ </pre>
500
+ <p>
501
+ If the action return nil, the normal get or post will be executed, else no.
502
+ </p>
503
+ <p><a class="source-toggle" href="#"
504
+ onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
505
+ <div class="method-source-code" id="M000013-source">
506
+ <pre>
507
+ <span class="ruby-comment cmt"># File lib/capcode/filters.rb, line 14</span>
508
+ 14: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">before_filter</span>( <span class="ruby-identifier">action</span>, <span class="ruby-identifier">opts</span> = {} )
509
+ 15: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Filter</span>.<span class="ruby-identifier">filters</span>[<span class="ruby-identifier">action</span>] = { }
510
+ 16:
511
+ 17: <span class="ruby-identifier">opts</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>
512
+ 18: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Filter</span>.<span class="ruby-identifier">filters</span>[<span class="ruby-identifier">action</span>][<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
513
+ 19: <span class="ruby-keyword kw">end</span>
514
+ 20: <span class="ruby-keyword kw">end</span>
463
515
  </pre>
464
516
  </div>
465
517
  </div>
@@ -482,10 +534,10 @@ Hash containing all the environment variables
482
534
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
483
535
  <div class="method-source-code" id="M000003-source">
484
536
  <pre>
485
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 352</span>
486
- 352: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
487
- 353: <span class="ruby-ivar">@env</span>
488
- 354: <span class="ruby-keyword kw">end</span>
537
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 370</span>
538
+ 370: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
539
+ 371: <span class="ruby-ivar">@env</span>
540
+ 372: <span class="ruby-keyword kw">end</span>
489
541
  </pre>
490
542
  </div>
491
543
  </div>
@@ -540,27 +592,27 @@ The block must return a Hash of username =&gt; password like that :
540
592
  onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
541
593
  <div class="method-source-code" id="M000009-source">
542
594
  <pre>
543
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 520</span>
544
- 520: <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> )
545
- 521: <span class="ruby-identifier">options</span> = {
546
- 522: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:basic</span>,
547
- 523: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;Capcode.app&quot;</span>,
548
- 524: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;opaque&quot;</span>,
549
- 525: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/&quot;</span>
550
- 526: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
551
- 527:
552
- 528: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
553
- 529:
554
- 530: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
555
- 531:
556
- 532: <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>
557
- 533: <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>
558
- 534: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
559
- 535: <span class="ruby-keyword kw">end</span>
560
- 536: <span class="ruby-keyword kw">else</span>
561
- 537: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
562
- 538: <span class="ruby-keyword kw">end</span>
563
- 539: <span class="ruby-keyword kw">end</span>
595
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 544</span>
596
+ 544: <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> )
597
+ 545: <span class="ruby-identifier">options</span> = {
598
+ 546: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:basic</span>,
599
+ 547: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;Capcode.app&quot;</span>,
600
+ 548: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;opaque&quot;</span>,
601
+ 549: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/&quot;</span>
602
+ 550: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
603
+ 551:
604
+ 552: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
605
+ 553:
606
+ 554: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
607
+ 555:
608
+ 556: <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>
609
+ 557: <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>
610
+ 558: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
611
+ 559: <span class="ruby-keyword kw">end</span>
612
+ 560: <span class="ruby-keyword kw">else</span>
613
+ 561: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
614
+ 562: <span class="ruby-keyword kw">end</span>
615
+ 563: <span class="ruby-keyword kw">end</span>
564
616
  </pre>
565
617
  </div>
566
618
  </div>
@@ -589,11 +641,11 @@ Rack or What you want Helper
589
641
  onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
590
642
  <div class="method-source-code" id="M000007-source">
591
643
  <pre>
592
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 484</span>
593
- 484: <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> )
594
- 485: <span class="ruby-comment cmt">#@@__ROUTES[route] = yield</span>
595
- 486: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">route</span>] = <span class="ruby-keyword kw">yield</span>
596
- 487: <span class="ruby-keyword kw">end</span>
644
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 508</span>
645
+ 508: <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> )
646
+ 509: <span class="ruby-comment cmt">#@@__ROUTES[route] = yield</span>
647
+ 510: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">route</span>] = <span class="ruby-keyword kw">yield</span>
648
+ 511: <span class="ruby-keyword kw">end</span>
597
649
  </pre>
598
650
  </div>
599
651
  </div>
@@ -617,10 +669,10 @@ parameters (GET or POST)
617
669
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
618
670
  <div class="method-source-code" id="M000002-source">
619
671
  <pre>
620
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 347</span>
621
- 347: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
622
- 348: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
623
- 349: <span class="ruby-keyword kw">end</span>
672
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 365</span>
673
+ 365: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
674
+ 366: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
675
+ 367: <span class="ruby-keyword kw">end</span>
624
676
  </pre>
625
677
  </div>
626
678
  </div>
@@ -643,10 +695,10 @@ Return the Rack::Request object
643
695
  onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
644
696
  <div class="method-source-code" id="M000005-source">
645
697
  <pre>
646
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 362</span>
647
- 362: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
648
- 363: <span class="ruby-ivar">@request</span>
649
- 364: <span class="ruby-keyword kw">end</span>
698
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 380</span>
699
+ 380: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
700
+ 381: <span class="ruby-ivar">@request</span>
701
+ 382: <span class="ruby-keyword kw">end</span>
650
702
  </pre>
651
703
  </div>
652
704
  </div>
@@ -669,10 +721,10 @@ Return the Rack::Response object
669
721
  onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
670
722
  <div class="method-source-code" id="M000006-source">
671
723
  <pre>
672
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 367</span>
673
- 367: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
674
- 368: <span class="ruby-ivar">@response</span>
675
- 369: <span class="ruby-keyword kw">end</span>
724
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 385</span>
725
+ 385: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
726
+ 386: <span class="ruby-ivar">@response</span>
727
+ 387: <span class="ruby-keyword kw">end</span>
676
728
  </pre>
677
729
  </div>
678
730
  </div>
@@ -693,7 +745,7 @@ Start your <a href="Capcode.html#M000010">application</a>.
693
745
  </p>
694
746
  <p>
695
747
  Options : see <a
696
- href="Capcode/Configuration.html#M000022">Capcode::Configuration.set</a>
748
+ href="Capcode/Configuration.html#M000023">Capcode::Configuration.set</a>
697
749
  </p>
698
750
  <p>
699
751
  Options <a href="Capcode.html#M000012">set</a> here replace the ones <a
@@ -703,131 +755,131 @@ href="Capcode.html#M000012">set</a> globally
703
755
  onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
704
756
  <div class="method-source-code" id="M000011-source">
705
757
  <pre>
706
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 616</span>
707
- 616: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
708
- 617: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
709
- 618:
710
- 619: <span class="ruby-comment cmt"># Parse options</span>
711
- 620: <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>
712
- 621: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
713
- 622: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
714
- 623: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
715
- 624:
716
- 625: <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> ) {
717
- 626: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:console</span>, <span class="ruby-keyword kw">true</span>
718
- 627: }
719
- 628: <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: #{Capcode::Configuration.get(:host)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
720
- 629: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:host</span>, <span class="ruby-identifier">h</span>
721
- 630: }
722
- 631: <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: #{Capcode::Configuration.get(:port)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
723
- 632: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:port</span>, <span class="ruby-identifier">p</span>
724
- 633: }
725
- 634: <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: #{Capcode::Configuration.get(:daemonize)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
726
- 635: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:daemonize</span>, <span class="ruby-identifier">d</span>
727
- 636: }
728
- 637: <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: #{Capcode::Configuration.get(:root)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
729
- 638: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:root</span>, <span class="ruby-identifier">w</span>
730
- 639: }
731
- 640: <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: #{Capcode::Configuration.get(:static)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
732
- 641: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:static</span>, <span class="ruby-identifier">r</span>
733
- 642: }
734
- 643:
735
- 644: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
736
- 645: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
737
- 646:
738
- 647: <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>
739
- 648: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
740
- 649: <span class="ruby-identifier">exit</span>
741
- 650: <span class="ruby-keyword kw">end</span>
742
- 651: <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>
743
- 652: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
744
- 653: <span class="ruby-identifier">exit</span>
745
- 654: <span class="ruby-keyword kw">end</span>
746
- 655: <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>
747
- 656: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:verbose</span>, <span class="ruby-keyword kw">true</span>
748
- 657: <span class="ruby-keyword kw">end</span>
749
- 658: <span class="ruby-keyword kw">end</span>
750
- 659:
751
- 660: <span class="ruby-keyword kw">begin</span>
752
- 661: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
753
- 662: <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>
754
- 663: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
755
- 664: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
756
- 665: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
757
- 666: <span class="ruby-keyword kw">end</span>
758
- 667:
759
- 668: <span class="ruby-comment cmt"># Run in the Working directory</span>
760
- 669: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Go on root directory (#{File.expand_path(Capcode::Configuration.get(:root))})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
761
- 670: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>) ) <span class="ruby-keyword kw">do</span>
762
- 671:
763
- 672: <span class="ruby-comment cmt"># Check that mongrel exists </span>
764
- 673: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>).<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>) <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
765
- 674: <span class="ruby-keyword kw">begin</span>
766
- 675: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
767
- 676: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:mongrel</span>
768
- 677: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
769
- 678: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
770
- 679: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:webrick</span>
771
- 680: <span class="ruby-keyword kw">end</span>
758
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 640</span>
759
+ 640: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
760
+ 641: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
761
+ 642:
762
+ 643: <span class="ruby-comment cmt"># Parse options</span>
763
+ 644: <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>
764
+ 645: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
765
+ 646: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
766
+ 647: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
767
+ 648:
768
+ 649: <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> ) {
769
+ 650: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:console</span>, <span class="ruby-keyword kw">true</span>
770
+ 651: }
771
+ 652: <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: #{Capcode::Configuration.get(:host)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
772
+ 653: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:host</span>, <span class="ruby-identifier">h</span>
773
+ 654: }
774
+ 655: <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: #{Capcode::Configuration.get(:port)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
775
+ 656: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:port</span>, <span class="ruby-identifier">p</span>
776
+ 657: }
777
+ 658: <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: #{Capcode::Configuration.get(:daemonize)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
778
+ 659: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:daemonize</span>, <span class="ruby-identifier">d</span>
779
+ 660: }
780
+ 661: <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: #{Capcode::Configuration.get(:root)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
781
+ 662: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:root</span>, <span class="ruby-identifier">w</span>
782
+ 663: }
783
+ 664: <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: #{Capcode::Configuration.get(:static)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
784
+ 665: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:static</span>, <span class="ruby-identifier">r</span>
785
+ 666: }
786
+ 667:
787
+ 668: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
788
+ 669: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
789
+ 670:
790
+ 671: <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>
791
+ 672: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
792
+ 673: <span class="ruby-identifier">exit</span>
793
+ 674: <span class="ruby-keyword kw">end</span>
794
+ 675: <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>
795
+ 676: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
796
+ 677: <span class="ruby-identifier">exit</span>
797
+ 678: <span class="ruby-keyword kw">end</span>
798
+ 679: <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>
799
+ 680: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:verbose</span>, <span class="ruby-keyword kw">true</span>
772
800
  681: <span class="ruby-keyword kw">end</span>
773
- 682:
774
- 683: <span class="ruby-comment cmt"># From rackup !!!</span>
775
- 684: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:daemonize</span>)
776
- 685: <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>
777
- 686: <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>
778
- 687: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
779
- 688: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
780
- 689: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
781
- 690: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
782
- 691: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
783
- 692: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
784
- 693: <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>
785
- 694: <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>
786
- 695: <span class="ruby-keyword kw">else</span>
787
- 696: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
788
- 697: <span class="ruby-keyword kw">end</span>
789
- 698: <span class="ruby-keyword kw">else</span>
790
- 699: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
791
- 700: <span class="ruby-keyword kw">end</span>
792
- 701:
793
- 702: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</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>) }
794
- 703: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>)) }
795
- 704: <span class="ruby-keyword kw">end</span>
796
- 705:
797
- 706: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
798
- 707: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
799
- 708: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
800
- 709: <span class="ruby-keyword kw">else</span>
801
- 710: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>)
802
- 711: <span class="ruby-keyword kw">end</span>
803
- 712: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>)) )
804
- 713:
805
- 714: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:console</span>)
806
- 715: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
807
- 716: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
808
- 717: <span class="ruby-identifier">exit</span>
809
- 718: <span class="ruby-keyword kw">end</span>
810
- 719:
811
- 720: <span class="ruby-comment cmt"># Start server</span>
812
- 721: <span class="ruby-keyword kw">case</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>).<span class="ruby-identifier">to_s</span>
813
- 722: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
814
- 723: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
815
- 724: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
816
- 725: <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> }
817
- 726: }
818
- 727: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
819
- 728: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
820
- 729: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
821
- 730: <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> }
822
- 731: }
823
- 732: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;thin&quot;</span>
824
- 733: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
825
- 734: <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">Thin</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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
826
- 735: <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> }
827
- 736: }
828
- 737: <span class="ruby-keyword kw">end</span>
829
- 738: <span class="ruby-keyword kw">end</span>
830
- 739: <span class="ruby-keyword kw">end</span>
801
+ 682: <span class="ruby-keyword kw">end</span>
802
+ 683:
803
+ 684: <span class="ruby-keyword kw">begin</span>
804
+ 685: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
805
+ 686: <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>
806
+ 687: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
807
+ 688: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
808
+ 689: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
809
+ 690: <span class="ruby-keyword kw">end</span>
810
+ 691:
811
+ 692: <span class="ruby-comment cmt"># Run in the Working directory</span>
812
+ 693: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Go on root directory (#{File.expand_path(Capcode::Configuration.get(:root))})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
813
+ 694: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>) ) <span class="ruby-keyword kw">do</span>
814
+ 695:
815
+ 696: <span class="ruby-comment cmt"># Check that mongrel exists </span>
816
+ 697: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>).<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>) <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
817
+ 698: <span class="ruby-keyword kw">begin</span>
818
+ 699: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
819
+ 700: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:mongrel</span>
820
+ 701: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
821
+ 702: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
822
+ 703: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:webrick</span>
823
+ 704: <span class="ruby-keyword kw">end</span>
824
+ 705: <span class="ruby-keyword kw">end</span>
825
+ 706:
826
+ 707: <span class="ruby-comment cmt"># From rackup !!!</span>
827
+ 708: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:daemonize</span>)
828
+ 709: <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>
829
+ 710: <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>
830
+ 711: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
831
+ 712: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
832
+ 713: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
833
+ 714: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
834
+ 715: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
835
+ 716: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
836
+ 717: <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>
837
+ 718: <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>
838
+ 719: <span class="ruby-keyword kw">else</span>
839
+ 720: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
840
+ 721: <span class="ruby-keyword kw">end</span>
841
+ 722: <span class="ruby-keyword kw">else</span>
842
+ 723: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
843
+ 724: <span class="ruby-keyword kw">end</span>
844
+ 725:
845
+ 726: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</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>) }
846
+ 727: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>)) }
847
+ 728: <span class="ruby-keyword kw">end</span>
848
+ 729:
849
+ 730: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
850
+ 731: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
851
+ 732: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
852
+ 733: <span class="ruby-keyword kw">else</span>
853
+ 734: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>)
854
+ 735: <span class="ruby-keyword kw">end</span>
855
+ 736: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>)) )
856
+ 737:
857
+ 738: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:console</span>)
858
+ 739: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
859
+ 740: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
860
+ 741: <span class="ruby-identifier">exit</span>
861
+ 742: <span class="ruby-keyword kw">end</span>
862
+ 743:
863
+ 744: <span class="ruby-comment cmt"># Start server</span>
864
+ 745: <span class="ruby-keyword kw">case</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>).<span class="ruby-identifier">to_s</span>
865
+ 746: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
866
+ 747: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
867
+ 748: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
868
+ 749: <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> }
869
+ 750: }
870
+ 751: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
871
+ 752: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
872
+ 753: <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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
873
+ 754: <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> }
874
+ 755: }
875
+ 756: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;thin&quot;</span>
876
+ 757: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
877
+ 758: <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">Thin</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-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
878
+ 759: <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> }
879
+ 760: }
880
+ 761: <span class="ruby-keyword kw">end</span>
881
+ 762: <span class="ruby-keyword kw">end</span>
882
+ 763: <span class="ruby-keyword kw">end</span>
831
883
  </pre>
832
884
  </div>
833
885
  </div>
@@ -850,10 +902,10 @@ Session hash
850
902
  onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
851
903
  <div class="method-source-code" id="M000004-source">
852
904
  <pre>
853
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 357</span>
854
- 357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
855
- 358: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
856
- 359: <span class="ruby-keyword kw">end</span>
905
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 375</span>
906
+ 375: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
907
+ 376: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
908
+ 377: <span class="ruby-keyword kw">end</span>
857
909
  </pre>
858
910
  </div>
859
911
  </div>
@@ -909,10 +961,10 @@ Example :
909
961
  onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
910
962
  <div class="method-source-code" id="M000008-source">
911
963
  <pre>
912
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 499</span>
913
- 499: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use</span>(<span class="ruby-identifier">middleware</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
914
- 500: <span class="ruby-identifier">middlewares</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span>]
915
- 501: <span class="ruby-keyword kw">end</span>
964
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 523</span>
965
+ 523: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use</span>(<span class="ruby-identifier">middleware</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
966
+ 524: <span class="ruby-identifier">middlewares</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span>]
967
+ 525: <span class="ruby-keyword kw">end</span>
916
968
  </pre>
917
969
  </div>
918
970
  </div>