Capcode 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,10 @@ Capcode is a web microframework
12
12
 
13
13
  == FEATURES/PROBLEMS:
14
14
 
15
+ === 0.9.9
16
+ * Better static files support {See example static.rb}[http://github.com/glejeune/Capcode/tree/master/examples/static.rb]
17
+ * Rewrite routes loader
18
+
15
19
  === 0.9.8
16
20
  * Add "any" to easly replace an <tt>alias_method :post, :get</tt>
17
21
  * Bug correction in Filter : actions are now executed in the order they are declared
@@ -142,6 +142,7 @@ Module <a href="Capcode/Views.html" class="link">Capcode::Views</a><br />
142
142
  Class <a href="Capcode/Base.html" class="link">Capcode::Base</a><br />
143
143
  Class <a href="Capcode/Configuration.html" class="link">Capcode::Configuration</a><br />
144
144
  Class <a href="Capcode/HTTPError.html" class="link">Capcode::HTTPError</a><br />
145
+ Class <a href="Capcode/StaticFiles.html" class="link">Capcode::StaticFiles</a><br />
145
146
 
146
147
  </div>
147
148
 
@@ -221,176 +222,199 @@ If the regexp in the route does not match, all arguments will be
221
222
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
222
223
  <div class="method-source-code" id="M000001-source">
223
224
  <pre>
224
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 368</span>
225
- 368: <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>
226
- 369: <span class="ruby-identifier">create_path</span> = <span class="ruby-identifier">routes_paths</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">nil?</span>
227
- 370: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
228
- 371: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
229
- 372: <span class="ruby-identifier">routes_paths</span> = [<span class="ruby-value str">'/'</span><span class="ruby-operator">+</span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^Capcode::/</span>, <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">underscore</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">create_path</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
230
- 373: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/</span>
231
- 374: <span class="ruby-comment cmt"># # =&gt; [ {'/hello/world' =&gt; '([^\/]*)/id(\d*)', '/hello' =&gt; '(.*)'}, </span>
232
- 375: <span class="ruby-comment cmt"># 2, </span>
233
- 376: <span class="ruby-comment cmt"># &lt;Capcode::Klass&gt;, </span>
234
- 377: <span class="ruby-comment cmt"># {:agent =&gt; /Songbird (\d\.\d)[\d\/]*?/} ]</span>
235
- 378: <span class="ruby-identifier">hash_of_routes</span> = {}
236
- 379: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
237
- 380: <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>
238
- 381: <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>
239
- 382: <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> )
240
- 383: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
241
- 384: <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>)
242
- 385: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
243
- 386: <span class="ruby-keyword kw">else</span>
244
- 387: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
245
- 388: <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>
246
- 389: <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>)
247
- 390: <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>]
248
- 391: <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>
249
- 392: <span class="ruby-keyword kw">end</span>
250
- 393: <span class="ruby-keyword kw">else</span>
251
- 394: <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>
252
- 395: <span class="ruby-keyword kw">end</span>
253
- 396: <span class="ruby-keyword kw">end</span>
254
- 397: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
255
- 398: }
256
- 399:
257
- 400: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
258
- 401: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
259
- 402: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
260
- 403: <span class="ruby-keyword kw">end</span>
261
- 404:
262
- 405: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
263
- 406: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
264
- 407: <span class="ruby-ivar">@env</span>
265
- 408: <span class="ruby-keyword kw">end</span>
266
- 409:
267
- 410: <span class="ruby-comment cmt"># Session hash</span>
268
- 411: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
269
- 412: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
270
- 413: <span class="ruby-keyword kw">end</span>
271
- 414:
272
- 415: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
273
- 416: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
274
- 417: <span class="ruby-ivar">@request</span>
275
- 418: <span class="ruby-keyword kw">end</span>
276
- 419:
277
- 420: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
278
- 421: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
279
- 422: <span class="ruby-ivar">@response</span>
280
- 423: <span class="ruby-keyword kw">end</span>
281
- 424:
282
- 425: <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>
283
- 426: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
284
- 427: <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>
285
- 428: <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>)
286
- 429:
287
- 430: <span class="ruby-comment cmt"># Check authz</span>
288
- 431: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
289
- 432: <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>
290
- 433: <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>
291
- 434: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
292
- 435: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
293
- 436:
294
- 437: <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>
295
- 438: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">&quot;^#{r.gsub(/\/$/, &quot;&quot;)}([/]{1}.*)?$&quot;</span>
296
- 439: <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> )
297
- 440: <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>
298
- 441: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
299
- 442: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
300
- 443: <span class="ruby-keyword kw">end</span>
301
- 444: <span class="ruby-keyword kw">end</span>
302
- 445: <span class="ruby-keyword kw">end</span>
303
- 446: <span class="ruby-keyword kw">end</span>
304
- 447: <span class="ruby-keyword kw">end</span>
305
- 448:
306
- 449: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
307
- 450: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
308
- 451: <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>] ) {
309
- 452: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
310
- 453: }
311
- 454: <span class="ruby-keyword kw">end</span>
312
- 455:
313
- 456: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
314
- 457: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
315
- 458: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
316
- 459:
317
- 460: <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> )
318
- 461: <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>
319
- 462: <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> )
320
- 463: <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>
321
- 464: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
322
- 465: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
323
- 466: <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>
324
- 467: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
325
- 468: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
326
- 469: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
327
- 470: <span class="ruby-keyword kw">end</span>
328
- 471: <span class="ruby-keyword kw">end</span>
329
- 472: <span class="ruby-keyword kw">end</span>
330
- 473:
331
- 474: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">finalNArgs</span> <span class="ruby-operator">&gt;</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
- 475: <span class="ruby-keyword kw">return</span> [<span class="ruby-value">404</span>, {<span class="ruby-value str">'Content-Type'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'text/plain'</span>}, <span class="ruby-node">&quot;Not Found: #{@request.path}&quot;</span>]
333
- 476: <span class="ruby-keyword kw">end</span>
334
- 477:
335
- 478: <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>]
336
- 479: <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>] )
337
- 480: <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> ) )
338
- 481: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
339
- 482: <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>
340
- 483: <span class="ruby-keyword kw">else</span>
341
- 484: <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> }
342
- 485: <span class="ruby-keyword kw">end</span>
343
- 486:
344
- 487: <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>
345
- 488: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
346
- 489: <span class="ruby-keyword kw">end</span>
347
- 490:
348
- 491: <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> )
349
- 492:
350
- 493: <span class="ruby-keyword kw">if</span>( <span class="ruby-identifier">filter_output</span>.<span class="ruby-identifier">nil?</span> )
351
- 494: <span class="ruby-comment cmt"># case @env[&quot;REQUEST_METHOD&quot;]</span>
352
- 495: <span class="ruby-comment cmt"># when &quot;GET&quot; </span>
353
- 496: <span class="ruby-comment cmt"># get( *args )</span>
354
- 497: <span class="ruby-comment cmt"># when &quot;POST&quot;</span>
355
- 498: <span class="ruby-comment cmt"># _method = params.delete( &quot;_method&quot; ) { |_| &quot;post&quot; }</span>
356
- 499: <span class="ruby-comment cmt"># send( _method.downcase.to_sym, *args )</span>
357
- 500: <span class="ruby-comment cmt"># else</span>
358
- 501: <span class="ruby-comment cmt"># _method = @env[&quot;REQUEST_METHOD&quot;]</span>
359
- 502: <span class="ruby-comment cmt"># send( _method.downcase.to_sym, *args )</span>
360
- 503: <span class="ruby-comment cmt"># end</span>
361
- 504: <span class="ruby-keyword kw">begin</span>
362
- 505: <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-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>] }
363
- 506: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">method_defined?</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span> )
364
- 507: <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> )
365
- 508: <span class="ruby-keyword kw">else</span>
366
- 509: <span class="ruby-identifier">any</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
367
- 510: <span class="ruby-keyword kw">end</span>
368
- 511: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
369
- 512: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>
370
- 513: <span class="ruby-keyword kw">end</span>
371
- 514: <span class="ruby-keyword kw">else</span>
372
- 515: <span class="ruby-identifier">filter_output</span>
373
- 516: <span class="ruby-keyword kw">end</span>
374
- 517: }
375
- 518:
376
- 519: <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>)
377
- 520: <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>
378
- 521: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
379
- 522: <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>
380
- 523: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
381
- 524: <span class="ruby-keyword kw">end</span>
382
- 525: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[2]</span>
383
- 526: <span class="ruby-keyword kw">else</span>
384
- 527: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
385
- 528: <span class="ruby-keyword kw">end</span>
386
- 529:
387
- 530: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
388
- 531: <span class="ruby-keyword kw">end</span>
389
- 532:
390
- 533: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
391
- 534: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
392
- 535: }
393
- 536: <span class="ruby-keyword kw">end</span>
225
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 396</span>
226
+ 396: <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>
227
+ 397: <span class="ruby-identifier">create_path</span> = <span class="ruby-identifier">routes_paths</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">nil?</span>
228
+ 398: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
229
+ 399: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
230
+ 400: <span class="ruby-identifier">routes_paths</span> = [<span class="ruby-value str">'/'</span><span class="ruby-operator">+</span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^Capcode::/</span>, <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">underscore</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">create_path</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
231
+ 401: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/</span>
232
+ 402: <span class="ruby-comment cmt"># # =&gt; [ {</span>
233
+ 403: <span class="ruby-comment cmt"># '/hello/world' =&gt; {</span>
234
+ 404: <span class="ruby-comment cmt"># :regexp =&gt; '([^\/]*)/id(\d*)',</span>
235
+ 405: <span class="ruby-comment cmt"># :route =&gt; '/hello/world/([^\/]*)/id(\d*)',</span>
236
+ 406: <span class="ruby-comment cmt"># :nargs =&gt; 2</span>
237
+ 407: <span class="ruby-comment cmt"># },</span>
238
+ 408: <span class="ruby-comment cmt"># '/hello/world' =&gt; {</span>
239
+ 409: <span class="ruby-comment cmt"># :regexp =&gt; '(.*)',</span>
240
+ 410: <span class="ruby-comment cmt"># :route =&gt; '/hello/(.*)',</span>
241
+ 411: <span class="ruby-comment cmt"># :nargs =&gt; 1</span>
242
+ 412: <span class="ruby-comment cmt"># }</span>
243
+ 413: <span class="ruby-comment cmt"># },</span>
244
+ 414: <span class="ruby-comment cmt"># 2, </span>
245
+ 415: <span class="ruby-comment cmt"># &lt;Capcode::Klass&gt;, </span>
246
+ 416: <span class="ruby-comment cmt"># {:agent =&gt; /Songbird (\d\.\d)[\d\/]*?/} ]</span>
247
+ 417: <span class="ruby-identifier">hash_of_routes</span> = {}
248
+ 418: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
249
+ 419: <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>
250
+ 420: <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>
251
+ 421: <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> )
252
+ 422: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
253
+ 423: <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>)
254
+ 424: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = {
255
+ 425: <span class="ruby-identifier">:regexp</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">''</span>,
256
+ 426: <span class="ruby-identifier">:route</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">current_route_path</span>,
257
+ 427: <span class="ruby-identifier">:nargs</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
258
+ 428: }
259
+ 429: <span class="ruby-keyword kw">else</span>
260
+ 430: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
261
+ 431: <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>
262
+ 432: <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>)
263
+ 433: <span class="ruby-identifier">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>
264
+ 434:
265
+ 435: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">_pre</span>] = {
266
+ 436: <span class="ruby-identifier">:regexp</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>],
267
+ 437: <span class="ruby-identifier">:route</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">current_route_path</span>,
268
+ 438: <span class="ruby-identifier">:nargs</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">captures_for_routes</span>
269
+ 439: }
270
+ 440: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-identifier">captures_for_routes</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-identifier">captures_for_routes</span>
271
+ 441: <span class="ruby-keyword kw">end</span>
272
+ 442: <span class="ruby-keyword kw">else</span>
273
+ 443: <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>
274
+ 444: <span class="ruby-keyword kw">end</span>
275
+ 445: <span class="ruby-keyword kw">end</span>
276
+ 446: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
277
+ 447: }
278
+ 448:
279
+ 449: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
280
+ 450: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
281
+ 451: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
282
+ 452: <span class="ruby-keyword kw">end</span>
283
+ 453:
284
+ 454: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
285
+ 455: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
286
+ 456: <span class="ruby-ivar">@env</span>
287
+ 457: <span class="ruby-keyword kw">end</span>
288
+ 458:
289
+ 459: <span class="ruby-comment cmt"># Session hash</span>
290
+ 460: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
291
+ 461: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
292
+ 462: <span class="ruby-keyword kw">end</span>
293
+ 463:
294
+ 464: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
295
+ 465: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
296
+ 466: <span class="ruby-ivar">@request</span>
297
+ 467: <span class="ruby-keyword kw">end</span>
298
+ 468:
299
+ 469: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
300
+ 470: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
301
+ 471: <span class="ruby-ivar">@response</span>
302
+ 472: <span class="ruby-keyword kw">end</span>
303
+ 473:
304
+ 474: <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>
305
+ 475: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
306
+ 476: <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>
307
+ 477: <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>)
308
+ 478:
309
+ 479: <span class="ruby-comment cmt"># Check authz</span>
310
+ 480: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
311
+ 481: <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>
312
+ 482: <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>
313
+ 483: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
314
+ 484: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
315
+ 485:
316
+ 486: <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>
317
+ 487: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">&quot;^#{r.gsub(/\/$/, &quot;&quot;)}([/]{1}.*)?$&quot;</span>
318
+ 488: <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> )
319
+ 489: <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>
320
+ 490: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
321
+ 491: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
322
+ 492: <span class="ruby-keyword kw">end</span>
323
+ 493: <span class="ruby-keyword kw">end</span>
324
+ 494: <span class="ruby-keyword kw">end</span>
325
+ 495: <span class="ruby-keyword kw">end</span>
326
+ 496: <span class="ruby-keyword kw">end</span>
327
+ 497:
328
+ 498: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
329
+ 499: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
330
+ 500: <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>] ) {
331
+ 501: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
332
+ 502: }
333
+ 503: <span class="ruby-keyword kw">end</span>
334
+ 504:
335
+ 505: <span class="ruby-identifier">max_match_size</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>]
336
+ 506: <span class="ruby-identifier">match_distance</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>]
337
+ 507:
338
+ 508: <span class="ruby-identifier">result_route</span> = <span class="ruby-keyword kw">nil</span>
339
+ 509: <span class="ruby-identifier">result_nargs</span> = <span class="ruby-keyword kw">nil</span>
340
+ 510: <span class="ruby-identifier">result_args</span> = []
341
+ 511:
342
+ 512: <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">route</span>, <span class="ruby-identifier">data</span><span class="ruby-operator">|</span>
343
+ 513: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;^&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">data</span>[<span class="ruby-identifier">:route</span>]<span class="ruby-operator">+</span><span class="ruby-value str">&quot;$&quot;</span>)
344
+ 514:
345
+ 515: <span class="ruby-identifier">matching</span> = <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>(<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>)
346
+ 516: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">matching</span>.<span class="ruby-identifier">nil?</span>
347
+ 517:
348
+ 518: <span class="ruby-identifier">result_args</span> = <span class="ruby-identifier">matching</span>.<span class="ruby-identifier">to_a</span>
349
+ 519: <span class="ruby-identifier">result_args</span>.<span class="ruby-identifier">shift</span>
350
+ 520: <span class="ruby-identifier">match_size</span> = <span class="ruby-identifier">matching</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
351
+ 521:
352
+ 522: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">match_size</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">max_match_size</span>
353
+ 523: <span class="ruby-comment cmt"># OK Terminé</span>
354
+ 524: <span class="ruby-identifier">result_route</span> = <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:route</span>]
355
+ 525: <span class="ruby-identifier">result_nargs</span> = <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:nargs</span>]
356
+ 526:
357
+ 527: <span class="ruby-keyword kw">break</span>
358
+ 528: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">max_match_size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">match_size</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">match_distance</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">max_match_size</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">match_size</span>
359
+ 529: <span class="ruby-identifier">match_distance</span> = <span class="ruby-identifier">max_match_size</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">match_size</span>
360
+ 530:
361
+ 531: <span class="ruby-identifier">result_route</span> = <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:route</span>]
362
+ 532: <span class="ruby-identifier">result_nargs</span> = <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:nargs</span>]
363
+ 533: <span class="ruby-keyword kw">end</span>
364
+ 534: <span class="ruby-keyword kw">end</span>
365
+ 535:
366
+ 536: <span class="ruby-keyword kw">return</span> [<span class="ruby-value">404</span>, {<span class="ruby-value str">'Content-Type'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'text/plain'</span>}, <span class="ruby-node">&quot;Not Found: #{@request.path}&quot;</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result_route</span>.<span class="ruby-identifier">nil?</span>
367
+ 537:
368
+ 538: <span class="ruby-identifier">result_args</span> = <span class="ruby-identifier">result_args</span> <span class="ruby-operator">+</span> <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">max_match_size</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">result_nargs</span>)
369
+ 539:
370
+ 540: <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> )
371
+ 541:
372
+ 542: <span class="ruby-keyword kw">if</span>( <span class="ruby-identifier">filter_output</span>.<span class="ruby-identifier">nil?</span> )
373
+ 543: <span class="ruby-comment cmt"># case @env[&quot;REQUEST_METHOD&quot;]</span>
374
+ 544: <span class="ruby-comment cmt"># when &quot;GET&quot; </span>
375
+ 545: <span class="ruby-comment cmt"># get( *args )</span>
376
+ 546: <span class="ruby-comment cmt"># when &quot;POST&quot;</span>
377
+ 547: <span class="ruby-comment cmt"># _method = params.delete( &quot;_method&quot; ) { |_| &quot;post&quot; }</span>
378
+ 548: <span class="ruby-comment cmt"># send( _method.downcase.to_sym, *args )</span>
379
+ 549: <span class="ruby-comment cmt"># else</span>
380
+ 550: <span class="ruby-comment cmt"># _method = @env[&quot;REQUEST_METHOD&quot;]</span>
381
+ 551: <span class="ruby-comment cmt"># send( _method.downcase.to_sym, *args )</span>
382
+ 552: <span class="ruby-comment cmt"># end</span>
383
+ 553: <span class="ruby-keyword kw">begin</span>
384
+ 554: <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-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>] }
385
+ 555: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">method_defined?</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span> )
386
+ 556: <span class="ruby-comment cmt"># send( _method.downcase.to_sym, *args )</span>
387
+ 557: <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">result_args</span> )
388
+ 558: <span class="ruby-keyword kw">else</span>
389
+ 559: <span class="ruby-comment cmt"># any( *args )</span>
390
+ 560: <span class="ruby-identifier">any</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">result_args</span> )
391
+ 561: <span class="ruby-keyword kw">end</span>
392
+ 562: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
393
+ 563: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>
394
+ 564: <span class="ruby-keyword kw">end</span>
395
+ 565: <span class="ruby-keyword kw">else</span>
396
+ 566: <span class="ruby-identifier">filter_output</span>
397
+ 567: <span class="ruby-keyword kw">end</span>
398
+ 568: }
399
+ 569:
400
+ 570: <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>)
401
+ 571: <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>
402
+ 572: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
403
+ 573: <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>
404
+ 574: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
405
+ 575: <span class="ruby-keyword kw">end</span>
406
+ 576: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[2]</span>
407
+ 577: <span class="ruby-keyword kw">else</span>
408
+ 578: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
409
+ 579: <span class="ruby-keyword kw">end</span>
410
+ 580:
411
+ 581: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
412
+ 582: <span class="ruby-keyword kw">end</span>
413
+ 583:
414
+ 584: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
415
+ 585: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
416
+ 586: }
417
+ 587: <span class="ruby-keyword kw">end</span>
394
418
  </pre>
395
419
  </div>
396
420
  </div>
@@ -411,7 +435,7 @@ Return the Rack App.
411
435
  </p>
412
436
  <p>
413
437
  Options : see <a
414
- href="Capcode/Configuration.html#M000026">Capcode::Configuration.set</a>
438
+ href="Capcode/Configuration.html#M000028">Capcode::Configuration.set</a>
415
439
  </p>
416
440
  <p>
417
441
  Options <a href="Capcode.html#M000013">set</a> here replace the ones <a
@@ -421,85 +445,85 @@ href="Capcode.html#M000013">set</a> globally
421
445
  onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
422
446
  <div class="method-source-code" id="M000010-source">
423
447
  <pre>
424
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 605</span>
425
- 605: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
426
- 606: <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>)
427
- 607: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">print_debug</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>)
428
- 608:
429
- 609: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">clone</span>.<span class="ruby-identifier">delete_if</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
430
- 610: <span class="ruby-keyword kw">not</span>( <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">k</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/Capcode/</span> ) <span class="ruby-keyword kw">or</span> [
431
- 611: <span class="ruby-value str">&quot;Filter&quot;</span>,
432
- 612: <span class="ruby-value str">&quot;Helpers&quot;</span>,
433
- 613: <span class="ruby-value str">&quot;RouteError&quot;</span>,
434
- 614: <span class="ruby-value str">&quot;Views&quot;</span>,
435
- 615: <span class="ruby-value str">&quot;ParameterError&quot;</span>,
436
- 616: <span class="ruby-value str">&quot;HTTPError&quot;</span>,
437
- 617: <span class="ruby-value str">&quot;Configuration&quot;</span>,
438
- 618: <span class="ruby-value str">&quot;MissingLibrary&quot;</span>,
439
- 619: <span class="ruby-value str">&quot;Route&quot;</span>,
440
- 620: <span class="ruby-value str">&quot;RenderError&quot;</span>
441
- 621: ].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>)
442
- 622: }.<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>
443
- 623: <span class="ruby-keyword kw">begin</span>
444
- 624: <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>
445
- 625: <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>
446
- 626: <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>
447
- 627: <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>
448
- 628: <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>)
449
- 629: <span class="ruby-comment cmt"># Capcode.routes[current_route_path] = klass.new</span>
450
- 630: <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>
451
- 631: <span class="ruby-keyword kw">end</span>
452
- 632: <span class="ruby-keyword kw">end</span>
453
- 633: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
454
- 634: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
455
- 635: <span class="ruby-keyword kw">end</span>
456
- 636: <span class="ruby-keyword kw">end</span>
457
- 637:
458
- 638: <span class="ruby-comment cmt"># Set Static directory</span>
459
- 639: <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>
460
- 640:
461
- 641: <span class="ruby-comment cmt"># Initialize Rack App</span>
462
- 642: <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>)
463
- 643: <span class="ruby-comment cmt"># app = Rack::URLMap.new(Capcode.routes)</span>
464
- 644: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Ext</span><span class="ruby-operator">::</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>)
465
- 645: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Initialize static directory (#{Capcode.static}) in #{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>)
466
- 646: <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>(
467
- 647: <span class="ruby-identifier">app</span>,
468
- 648: <span class="ruby-comment cmt">#:urls =&gt; [@@__STATIC_DIR], </span>
469
- 649: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
470
- 650: <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>))
471
- 651: ) <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>
472
- 652: <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>)
473
- 653: <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>) )
474
- 654: <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>)
475
- 655: <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>)
476
- 656: <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>)
477
- 657: <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>)
478
- 658: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
479
- 659: <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-ivar">@cclogger</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>)) )
480
- 660:
481
- 661: <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>
482
- 662: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
483
- 663: <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>)
484
- 664: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
485
- 665: <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> )
486
- 666: <span class="ruby-keyword kw">else</span>
487
- 667: <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> )
488
- 668: <span class="ruby-keyword kw">end</span>
489
- 669: <span class="ruby-keyword kw">end</span>
490
- 670:
491
- 671: <span class="ruby-comment cmt"># Start database</span>
492
- 672: <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>
493
- 673: <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>) )
494
- 674: <span class="ruby-keyword kw">end</span>
495
- 675:
496
- 676: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
497
- 677: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;** Execute block&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>)
498
- 678: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
499
- 679: <span class="ruby-keyword kw">end</span>
500
- 680:
501
- 681: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
502
- 682: <span class="ruby-keyword kw">end</span>
448
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 656</span>
449
+ 656: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
450
+ 657: <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>)
451
+ 658: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">print_debug</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>)
452
+ 659:
453
+ 660: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">clone</span>.<span class="ruby-identifier">delete_if</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
454
+ 661: <span class="ruby-keyword kw">not</span>( <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">k</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/Capcode/</span> ) <span class="ruby-keyword kw">or</span> [
455
+ 662: <span class="ruby-value str">&quot;Filter&quot;</span>,
456
+ 663: <span class="ruby-value str">&quot;Helpers&quot;</span>,
457
+ 664: <span class="ruby-value str">&quot;RouteError&quot;</span>,
458
+ 665: <span class="ruby-value str">&quot;Views&quot;</span>,
459
+ 666: <span class="ruby-value str">&quot;ParameterError&quot;</span>,
460
+ 667: <span class="ruby-value str">&quot;HTTPError&quot;</span>,
461
+ 668: <span class="ruby-value str">&quot;StaticFiles&quot;</span>,
462
+ 669: <span class="ruby-value str">&quot;Configuration&quot;</span>,
463
+ 670: <span class="ruby-value str">&quot;MissingLibrary&quot;</span>,
464
+ 671: <span class="ruby-value str">&quot;Route&quot;</span>,
465
+ 672: <span class="ruby-value str">&quot;RenderError&quot;</span>
466
+ 673: ].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>)
467
+ 674: }.<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>
468
+ 675: <span class="ruby-keyword kw">begin</span>
469
+ 676: <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>
470
+ 677: <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>
471
+ 678: <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>
472
+ 679: <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>)
473
+ 680: <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>
474
+ 681: <span class="ruby-keyword kw">end</span>
475
+ 682: <span class="ruby-keyword kw">end</span>
476
+ 683: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
477
+ 684: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
478
+ 685: <span class="ruby-keyword kw">end</span>
479
+ 686: <span class="ruby-keyword kw">end</span>
480
+ 687:
481
+ 688: <span class="ruby-comment cmt"># Set Static directory</span>
482
+ 689: <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>
483
+ 690:
484
+ 691: <span class="ruby-comment cmt"># Initialize Rack App</span>
485
+ 692: <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>)
486
+ 693: <span class="ruby-comment cmt"># app = Rack::URLMap.new(Capcode.routes)</span>
487
+ 694: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Ext</span><span class="ruby-operator">::</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>)
488
+ 695: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Initialize static directory (#{Capcode.static}) in #{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>)
489
+ 696: <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>(
490
+ 697: <span class="ruby-identifier">app</span>,
491
+ 698: <span class="ruby-comment cmt">#:urls =&gt; [@@__STATIC_DIR], </span>
492
+ 699: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
493
+ 700: <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>))
494
+ 701: ) <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>
495
+ 702: <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>)
496
+ 703: <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>) )
497
+ 704: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">StaticFiles</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
498
+ 705: <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>)
499
+ 706: <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>)
500
+ 707: <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>)
501
+ 708: <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>)
502
+ 709: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
503
+ 710: <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-ivar">@cclogger</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>)) )
504
+ 711:
505
+ 712: <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>
506
+ 713: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
507
+ 714: <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>)
508
+ 715: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
509
+ 716: <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> )
510
+ 717: <span class="ruby-keyword kw">else</span>
511
+ 718: <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> )
512
+ 719: <span class="ruby-keyword kw">end</span>
513
+ 720: <span class="ruby-keyword kw">end</span>
514
+ 721:
515
+ 722: <span class="ruby-comment cmt"># Start database</span>
516
+ 723: <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>
517
+ 724: <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>) )
518
+ 725: <span class="ruby-keyword kw">end</span>
519
+ 726:
520
+ 727: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
521
+ 728: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;** Execute block&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>)
522
+ 729: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
523
+ 730: <span class="ruby-keyword kw">end</span>
524
+ 731:
525
+ 732: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
526
+ 733: <span class="ruby-keyword kw">end</span>
503
527
  </pre>
504
528
  </div>
505
529
  </div>
@@ -564,10 +588,10 @@ Hash containing all the environment variables
564
588
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
565
589
  <div class="method-source-code" id="M000003-source">
566
590
  <pre>
567
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 406</span>
568
- 406: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
569
- 407: <span class="ruby-ivar">@env</span>
570
- 408: <span class="ruby-keyword kw">end</span>
591
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 455</span>
592
+ 455: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
593
+ 456: <span class="ruby-ivar">@env</span>
594
+ 457: <span class="ruby-keyword kw">end</span>
571
595
  </pre>
572
596
  </div>
573
597
  </div>
@@ -622,27 +646,27 @@ The block must return a Hash of username =&gt; password like that :
622
646
  onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
623
647
  <div class="method-source-code" id="M000009-source">
624
648
  <pre>
625
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 579</span>
626
- 579: <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> )
627
- 580: <span class="ruby-identifier">options</span> = {
628
- 581: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:basic</span>,
629
- 582: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;Capcode.app&quot;</span>,
630
- 583: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;opaque&quot;</span>,
631
- 584: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/&quot;</span>
632
- 585: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
633
- 586:
634
- 587: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
635
- 588:
636
- 589: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
637
- 590:
638
- 591: <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>
639
- 592: <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>
640
- 593: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
641
- 594: <span class="ruby-keyword kw">end</span>
642
- 595: <span class="ruby-keyword kw">else</span>
643
- 596: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
644
- 597: <span class="ruby-keyword kw">end</span>
645
- 598: <span class="ruby-keyword kw">end</span>
649
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 630</span>
650
+ 630: <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> )
651
+ 631: <span class="ruby-identifier">options</span> = {
652
+ 632: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:basic</span>,
653
+ 633: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;Capcode.app&quot;</span>,
654
+ 634: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;opaque&quot;</span>,
655
+ 635: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/&quot;</span>
656
+ 636: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
657
+ 637:
658
+ 638: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
659
+ 639:
660
+ 640: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
661
+ 641:
662
+ 642: <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>
663
+ 643: <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>
664
+ 644: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
665
+ 645: <span class="ruby-keyword kw">end</span>
666
+ 646: <span class="ruby-keyword kw">else</span>
667
+ 647: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
668
+ 648: <span class="ruby-keyword kw">end</span>
669
+ 649: <span class="ruby-keyword kw">end</span>
646
670
  </pre>
647
671
  </div>
648
672
  </div>
@@ -662,10 +686,10 @@ The block must return a Hash of username =&gt; password like that :
662
686
  onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
663
687
  <div class="method-source-code" id="M000012-source">
664
688
  <pre>
665
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 829</span>
666
- 829: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">logger</span>
667
- 830: <span class="ruby-ivar">@cclogger</span>
668
- 831: <span class="ruby-keyword kw">end</span>
689
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 884</span>
690
+ 884: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">logger</span>
691
+ 885: <span class="ruby-ivar">@cclogger</span>
692
+ 886: <span class="ruby-keyword kw">end</span>
669
693
  </pre>
670
694
  </div>
671
695
  </div>
@@ -694,10 +718,10 @@ Rack or What you want Helper
694
718
  onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
695
719
  <div class="method-source-code" id="M000007-source">
696
720
  <pre>
697
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 544</span>
698
- 544: <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> )
699
- 545: <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>
700
- 546: <span class="ruby-keyword kw">end</span>
721
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 595</span>
722
+ 595: <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> )
723
+ 596: <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>
724
+ 597: <span class="ruby-keyword kw">end</span>
701
725
  </pre>
702
726
  </div>
703
727
  </div>
@@ -721,10 +745,10 @@ parameters (GET or POST)
721
745
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
722
746
  <div class="method-source-code" id="M000002-source">
723
747
  <pre>
724
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 401</span>
725
- 401: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
726
- 402: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
727
- 403: <span class="ruby-keyword kw">end</span>
748
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 450</span>
749
+ 450: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
750
+ 451: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
751
+ 452: <span class="ruby-keyword kw">end</span>
728
752
  </pre>
729
753
  </div>
730
754
  </div>
@@ -747,10 +771,10 @@ Return the Rack::Request object
747
771
  onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
748
772
  <div class="method-source-code" id="M000005-source">
749
773
  <pre>
750
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 416</span>
751
- 416: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
752
- 417: <span class="ruby-ivar">@request</span>
753
- 418: <span class="ruby-keyword kw">end</span>
774
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 465</span>
775
+ 465: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
776
+ 466: <span class="ruby-ivar">@request</span>
777
+ 467: <span class="ruby-keyword kw">end</span>
754
778
  </pre>
755
779
  </div>
756
780
  </div>
@@ -773,10 +797,10 @@ Return the Rack::Response object
773
797
  onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
774
798
  <div class="method-source-code" id="M000006-source">
775
799
  <pre>
776
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 421</span>
777
- 421: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
778
- 422: <span class="ruby-ivar">@response</span>
779
- 423: <span class="ruby-keyword kw">end</span>
800
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 470</span>
801
+ 470: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
802
+ 471: <span class="ruby-ivar">@response</span>
803
+ 472: <span class="ruby-keyword kw">end</span>
780
804
  </pre>
781
805
  </div>
782
806
  </div>
@@ -797,7 +821,7 @@ Start your <a href="Capcode.html#M000010">application</a>.
797
821
  </p>
798
822
  <p>
799
823
  Options : see <a
800
- href="Capcode/Configuration.html#M000026">Capcode::Configuration.set</a>
824
+ href="Capcode/Configuration.html#M000028">Capcode::Configuration.set</a>
801
825
  </p>
802
826
  <p>
803
827
  Options <a href="Capcode.html#M000013">set</a> here replace the ones <a
@@ -807,142 +831,146 @@ href="Capcode.html#M000013">set</a> globally
807
831
  onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
808
832
  <div class="method-source-code" id="M000011-source">
809
833
  <pre>
810
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 689</span>
811
- 689: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
812
- 690: <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>)
813
- 691:
814
- 692: <span class="ruby-comment cmt"># Parse options</span>
815
- 693: <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>
816
- 694: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
817
- 695: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
818
- 696: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
819
- 697:
820
- 698: <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> ) {
821
- 699: <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>
822
- 700: }
823
- 701: <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>
824
- 702: <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>
825
- 703: }
826
- 704: <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>
827
- 705: <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>
828
- 706: }
829
- 707: <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>
830
- 708: <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>
831
- 709: }
832
- 710: <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>
833
- 711: <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>
834
- 712: }
835
- 713: <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>
836
- 714: <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>
837
- 715: }
838
- 716: <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;--server SERVER&quot;</span>, <span class="ruby-node">&quot;Server to use (default: #{Capcode::Configuration.get(:server)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
839
- 717: <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">r</span>
840
- 718: }
841
- 719:
842
- 720: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
843
- 721: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
844
- 722:
845
- 723: <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>
846
- 724: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
847
- 725: <span class="ruby-identifier">exit</span>
848
- 726: <span class="ruby-keyword kw">end</span>
849
- 727: <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>
850
- 728: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
851
- 729: <span class="ruby-identifier">exit</span>
852
- 730: <span class="ruby-keyword kw">end</span>
853
- 731: <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>
854
- 732: <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>
855
- 733: <span class="ruby-keyword kw">end</span>
856
- 734: <span class="ruby-keyword kw">end</span>
857
- 735:
858
- 736: <span class="ruby-keyword kw">begin</span>
859
- 737: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
860
- 738: <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>
861
- 739: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
862
- 740: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
863
- 741: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
864
- 742: <span class="ruby-keyword kw">end</span>
865
- 743:
866
- 744: <span class="ruby-comment cmt"># Run in the Working directory</span>
867
- 745: <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>)
868
- 746: <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>
869
- 747:
870
- 748: <span class="ruby-comment cmt"># Check that mongrel exists </span>
871
- 749: <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>
872
- 750: <span class="ruby-keyword kw">begin</span>
873
- 751: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
874
- 752: <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>
875
- 753: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
876
- 754: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
877
- 755: <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>
878
- 756: <span class="ruby-keyword kw">end</span>
879
- 757: <span class="ruby-keyword kw">end</span>
880
- 758:
881
- 759: <span class="ruby-comment cmt"># From rackup !!!</span>
882
- 760: <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>)
883
- 761: <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>
884
- 762: <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>
885
- 763: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
886
- 764: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
887
- 765: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
888
- 766: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
889
- 767: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
890
- 768: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
891
- 769: <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>
892
- 770: <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>
893
- 771: <span class="ruby-keyword kw">else</span>
894
- 772: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
895
- 773: <span class="ruby-keyword kw">end</span>
896
- 774: <span class="ruby-keyword kw">else</span>
897
- 775: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
898
- 776: <span class="ruby-keyword kw">end</span>
899
- 777:
900
- 778: <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>) }
901
- 779: <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>)) }
902
- 780: <span class="ruby-keyword kw">end</span>
903
- 781:
904
- 782: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
905
- 783: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
906
- 784: <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> ) }
907
- 785: <span class="ruby-keyword kw">else</span>
908
- 786: <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>)
909
- 787: <span class="ruby-keyword kw">end</span>
910
- 788:
911
- 789: <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>)
912
- 790: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
913
- 791: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
914
- 792: <span class="ruby-identifier">exit</span>
915
- 793: <span class="ruby-keyword kw">end</span>
916
- 794:
917
- 795: <span class="ruby-comment cmt"># Start server</span>
918
- 796: <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>
919
- 797: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
920
- 798: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
921
- 799: <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>
922
- 800: <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> }
923
- 801: }
924
- 802: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
925
- 803: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
926
- 804: <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>
927
- 805: <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> }
928
- 806: }
929
- 807: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;thin&quot;</span>
930
- 808: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
931
- 809: <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>
932
- 810: <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> }
933
- 811: }
934
- 812: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;unicorn&quot;</span>
935
- 813: <span class="ruby-identifier">require</span> <span class="ruby-value str">'unicorn/launcher'</span>
936
- 814: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Unicorn on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
937
- 815: <span class="ruby-constant">Unicorn</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:listeners</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>]} )
938
- 816: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;rainbows&quot;</span>
939
- 817: <span class="ruby-identifier">require</span> <span class="ruby-value str">'unicorn/launcher'</span>
940
- 818: <span class="ruby-identifier">require</span> <span class="ruby-value str">'rainbows'</span>
941
- 819: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Rainbow on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
942
- 820: <span class="ruby-constant">Rainbows</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:listeners</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>]} )
943
- 821: <span class="ruby-keyword kw">end</span>
944
- 822: <span class="ruby-keyword kw">end</span>
945
- 823: <span class="ruby-keyword kw">end</span>
834
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 740</span>
835
+ 740: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
836
+ 741: <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>)
837
+ 742:
838
+ 743: <span class="ruby-comment cmt"># Parse options</span>
839
+ 744: <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>
840
+ 745: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
841
+ 746: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
842
+ 747: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
843
+ 748:
844
+ 749: <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> ) {
845
+ 750: <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>
846
+ 751: }
847
+ 752: <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>
848
+ 753: <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>
849
+ 754: }
850
+ 755: <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>
851
+ 756: <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>
852
+ 757: }
853
+ 758: <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>
854
+ 759: <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>
855
+ 760: }
856
+ 761: <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>
857
+ 762: <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>
858
+ 763: }
859
+ 764: <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>
860
+ 765: <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>
861
+ 766: }
862
+ 767: <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;--server SERVER&quot;</span>, <span class="ruby-node">&quot;Server to use (default: #{Capcode::Configuration.get(:server)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
863
+ 768: <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">r</span>
864
+ 769: }
865
+ 770:
866
+ 771: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
867
+ 772: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
868
+ 773:
869
+ 774: <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>
870
+ 775: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
871
+ 776: <span class="ruby-identifier">exit</span>
872
+ 777: <span class="ruby-keyword kw">end</span>
873
+ 778: <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>
874
+ 779: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
875
+ 780: <span class="ruby-identifier">exit</span>
876
+ 781: <span class="ruby-keyword kw">end</span>
877
+ 782: <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>
878
+ 783: <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>
879
+ 784: <span class="ruby-keyword kw">end</span>
880
+ 785: <span class="ruby-keyword kw">end</span>
881
+ 786:
882
+ 787: <span class="ruby-keyword kw">begin</span>
883
+ 788: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
884
+ 789: <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>
885
+ 790: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
886
+ 791: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
887
+ 792: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
888
+ 793: <span class="ruby-keyword kw">end</span>
889
+ 794:
890
+ 795: <span class="ruby-comment cmt"># Run in the Working directory</span>
891
+ 796: <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>)
892
+ 797: <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>
893
+ 798:
894
+ 799: <span class="ruby-comment cmt"># Check that mongrel exists </span>
895
+ 800: <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>
896
+ 801: <span class="ruby-keyword kw">begin</span>
897
+ 802: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
898
+ 803: <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>
899
+ 804: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
900
+ 805: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
901
+ 806: <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>
902
+ 807: <span class="ruby-keyword kw">end</span>
903
+ 808: <span class="ruby-keyword kw">end</span>
904
+ 809:
905
+ 810: <span class="ruby-comment cmt"># From rackup !!!</span>
906
+ 811: <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>)
907
+ 812: <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>
908
+ 813: <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>
909
+ 814: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
910
+ 815: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
911
+ 816: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
912
+ 817: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
913
+ 818: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
914
+ 819: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
915
+ 820: <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>
916
+ 821: <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>
917
+ 822: <span class="ruby-keyword kw">else</span>
918
+ 823: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
919
+ 824: <span class="ruby-keyword kw">end</span>
920
+ 825: <span class="ruby-keyword kw">else</span>
921
+ 826: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
922
+ 827: <span class="ruby-keyword kw">end</span>
923
+ 828:
924
+ 829: <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>) }
925
+ 830: <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>)) }
926
+ 831: <span class="ruby-keyword kw">end</span>
927
+ 832:
928
+ 833: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
929
+ 834: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
930
+ 835: <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> ) }
931
+ 836: <span class="ruby-keyword kw">else</span>
932
+ 837: <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>)
933
+ 838: <span class="ruby-keyword kw">end</span>
934
+ 839:
935
+ 840: <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>)
936
+ 841: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
937
+ 842: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
938
+ 843: <span class="ruby-identifier">exit</span>
939
+ 844: <span class="ruby-keyword kw">end</span>
940
+ 845:
941
+ 846: <span class="ruby-comment cmt"># Start server</span>
942
+ 847: <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>
943
+ 848: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
944
+ 849: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
945
+ 850: <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>
946
+ 851: <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> }
947
+ 852: }
948
+ 853: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
949
+ 854: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
950
+ 855: <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>
951
+ 856: <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> }
952
+ 857: }
953
+ 858: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;thin&quot;</span>
954
+ 859: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
955
+ 860: <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>
956
+ 861: <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> }
957
+ 862: }
958
+ 863: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;unicorn&quot;</span>
959
+ 864: <span class="ruby-identifier">require</span> <span class="ruby-value str">'unicorn/launcher'</span>
960
+ 865: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Unicorn on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
961
+ 866: <span class="ruby-constant">Unicorn</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:listeners</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>]} )
962
+ 867: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;rainbows&quot;</span>
963
+ 868: <span class="ruby-identifier">require</span> <span class="ruby-value str">'unicorn/launcher'</span>
964
+ 869: <span class="ruby-identifier">require</span> <span class="ruby-value str">'rainbows'</span>
965
+ 870: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Rainbow on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
966
+ 871: <span class="ruby-constant">Rainbows</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:listeners</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>]} )
967
+ 872: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;control_tower&quot;</span>
968
+ 873: <span class="ruby-identifier">require</span> <span class="ruby-value str">'control_tower'</span>
969
+ 874: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting ControlTower on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
970
+ 875: <span class="ruby-constant">ControlTower</span><span class="ruby-operator">::</span><span class="ruby-constant">Server</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</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-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">start</span>
971
+ 876: <span class="ruby-keyword kw">end</span>
972
+ 877: <span class="ruby-keyword kw">end</span>
973
+ 878: <span class="ruby-keyword kw">end</span>
946
974
  </pre>
947
975
  </div>
948
976
  </div>
@@ -965,10 +993,10 @@ Session hash
965
993
  onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
966
994
  <div class="method-source-code" id="M000004-source">
967
995
  <pre>
968
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 411</span>
969
- 411: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
970
- 412: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
971
- 413: <span class="ruby-keyword kw">end</span>
996
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 460</span>
997
+ 460: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
998
+ 461: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
999
+ 462: <span class="ruby-keyword kw">end</span>
972
1000
  </pre>
973
1001
  </div>
974
1002
  </div>
@@ -1024,10 +1052,10 @@ Example :
1024
1052
  onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
1025
1053
  <div class="method-source-code" id="M000008-source">
1026
1054
  <pre>
1027
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 558</span>
1028
- 558: <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>)
1029
- 559: <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>]
1030
- 560: <span class="ruby-keyword kw">end</span>
1055
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 609</span>
1056
+ 609: <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>)
1057
+ 610: <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>]
1058
+ 611: <span class="ruby-keyword kw">end</span>
1031
1059
  </pre>
1032
1060
  </div>
1033
1061
  </div>