Capcode 0.9.5 → 0.9.6

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.6
16
+ * More debug trace
17
+ * Bug correction in the custom version of Rack::URLmap
18
+
15
19
  === 0.9.5
16
20
  * Major bug correction
17
21
 
@@ -400,7 +400,7 @@ Return the Rack App.
400
400
  </p>
401
401
  <p>
402
402
  Options : see <a
403
- href="Capcode/Configuration.html#M000023">Capcode::Configuration.set</a>
403
+ href="Capcode/Configuration.html#M000024">Capcode::Configuration.set</a>
404
404
  </p>
405
405
  <p>
406
406
  Options <a href="Capcode.html#M000012">set</a> here replace the ones <a
@@ -413,80 +413,81 @@ href="Capcode.html#M000012">set</a> globally
413
413
  <span class="ruby-comment cmt"># File lib/capcode.rb, line 590</span>
414
414
  590: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
415
415
  591: <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>)
416
- 592:
417
- 593: <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>
418
- 594: <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> [
419
- 595: <span class="ruby-value str">&quot;Filter&quot;</span>,
420
- 596: <span class="ruby-value str">&quot;Helpers&quot;</span>,
421
- 597: <span class="ruby-value str">&quot;RouteError&quot;</span>,
422
- 598: <span class="ruby-value str">&quot;Views&quot;</span>,
423
- 599: <span class="ruby-value str">&quot;ParameterError&quot;</span>,
424
- 600: <span class="ruby-value str">&quot;HTTPError&quot;</span>,
425
- 601: <span class="ruby-value str">&quot;Configuration&quot;</span>,
426
- 602: <span class="ruby-value str">&quot;MissingLibrary&quot;</span>,
427
- 603: <span class="ruby-value str">&quot;Route&quot;</span>,
428
- 604: <span class="ruby-value str">&quot;RenderError&quot;</span>
429
- 605: ].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>)
430
- 606: }.<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>
431
- 607: <span class="ruby-keyword kw">begin</span>
432
- 608: <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>
433
- 609: <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>
434
- 610: <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>
435
- 611: <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>
436
- 612: <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>)
437
- 613: <span class="ruby-comment cmt"># Capcode.routes[current_route_path] = klass.new</span>
438
- 614: <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>
439
- 615: <span class="ruby-keyword kw">end</span>
440
- 616: <span class="ruby-keyword kw">end</span>
441
- 617: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
442
- 618: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
443
- 619: <span class="ruby-keyword kw">end</span>
444
- 620: <span class="ruby-keyword kw">end</span>
445
- 621:
446
- 622: <span class="ruby-comment cmt"># Set Static directory</span>
447
- 623: <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>
448
- 624:
449
- 625: <span class="ruby-comment cmt"># Initialize Rack App</span>
450
- 626: <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>)
451
- 627: <span class="ruby-comment cmt"># app = Rack::URLMap.new(Capcode.routes)</span>
452
- 628: <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>)
453
- 629: <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>)
454
- 630: <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>(
455
- 631: <span class="ruby-identifier">app</span>,
456
- 632: <span class="ruby-comment cmt">#:urls =&gt; [@@__STATIC_DIR], </span>
457
- 633: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
458
- 634: <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>))
459
- 635: ) <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
- 636: <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>)
461
- 637: <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>) )
462
- 638: <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>)
463
- 639: <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>)
464
- 640: <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>)
465
- 641: <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>)
466
- 642: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
467
- 643:
468
- 644: <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>
469
- 645: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
470
- 646: <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>)
471
- 647: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
472
- 648: <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> )
473
- 649: <span class="ruby-keyword kw">else</span>
474
- 650: <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> )
475
- 651: <span class="ruby-keyword kw">end</span>
476
- 652: <span class="ruby-keyword kw">end</span>
477
- 653:
478
- 654: <span class="ruby-comment cmt"># Start database</span>
479
- 655: <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>
480
- 656: <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>) )
481
- 657: <span class="ruby-keyword kw">end</span>
482
- 658:
483
- 659: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
484
- 660: <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>)
485
- 661: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
486
- 662: <span class="ruby-keyword kw">end</span>
487
- 663:
488
- 664: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
489
- 665: <span class="ruby-keyword kw">end</span>
416
+ 592: <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>)
417
+ 593:
418
+ 594: <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>
419
+ 595: <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> [
420
+ 596: <span class="ruby-value str">&quot;Filter&quot;</span>,
421
+ 597: <span class="ruby-value str">&quot;Helpers&quot;</span>,
422
+ 598: <span class="ruby-value str">&quot;RouteError&quot;</span>,
423
+ 599: <span class="ruby-value str">&quot;Views&quot;</span>,
424
+ 600: <span class="ruby-value str">&quot;ParameterError&quot;</span>,
425
+ 601: <span class="ruby-value str">&quot;HTTPError&quot;</span>,
426
+ 602: <span class="ruby-value str">&quot;Configuration&quot;</span>,
427
+ 603: <span class="ruby-value str">&quot;MissingLibrary&quot;</span>,
428
+ 604: <span class="ruby-value str">&quot;Route&quot;</span>,
429
+ 605: <span class="ruby-value str">&quot;RenderError&quot;</span>
430
+ 606: ].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>)
431
+ 607: }.<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>
432
+ 608: <span class="ruby-keyword kw">begin</span>
433
+ 609: <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>
434
+ 610: <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>
435
+ 611: <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>
436
+ 612: <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>
437
+ 613: <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>)
438
+ 614: <span class="ruby-comment cmt"># Capcode.routes[current_route_path] = klass.new</span>
439
+ 615: <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>
440
+ 616: <span class="ruby-keyword kw">end</span>
441
+ 617: <span class="ruby-keyword kw">end</span>
442
+ 618: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
443
+ 619: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
444
+ 620: <span class="ruby-keyword kw">end</span>
445
+ 621: <span class="ruby-keyword kw">end</span>
446
+ 622:
447
+ 623: <span class="ruby-comment cmt"># Set Static directory</span>
448
+ 624: <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>
449
+ 625:
450
+ 626: <span class="ruby-comment cmt"># Initialize Rack App</span>
451
+ 627: <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>)
452
+ 628: <span class="ruby-comment cmt"># app = Rack::URLMap.new(Capcode.routes)</span>
453
+ 629: <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>)
454
+ 630: <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>)
455
+ 631: <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>(
456
+ 632: <span class="ruby-identifier">app</span>,
457
+ 633: <span class="ruby-comment cmt">#:urls =&gt; [@@__STATIC_DIR], </span>
458
+ 634: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
459
+ 635: <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>))
460
+ 636: ) <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>
461
+ 637: <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>)
462
+ 638: <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>) )
463
+ 639: <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>)
464
+ 640: <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>)
465
+ 641: <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>)
466
+ 642: <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>)
467
+ 643: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
468
+ 644:
469
+ 645: <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>
470
+ 646: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
471
+ 647: <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>)
472
+ 648: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
473
+ 649: <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> )
474
+ 650: <span class="ruby-keyword kw">else</span>
475
+ 651: <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> )
476
+ 652: <span class="ruby-keyword kw">end</span>
477
+ 653: <span class="ruby-keyword kw">end</span>
478
+ 654:
479
+ 655: <span class="ruby-comment cmt"># Start database</span>
480
+ 656: <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>
481
+ 657: <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>) )
482
+ 658: <span class="ruby-keyword kw">end</span>
483
+ 659:
484
+ 660: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
485
+ 661: <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>)
486
+ 662: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
487
+ 663: <span class="ruby-keyword kw">end</span>
488
+ 664:
489
+ 665: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
490
+ 666: <span class="ruby-keyword kw">end</span>
490
491
  </pre>
491
492
  </div>
492
493
  </div>
@@ -760,7 +761,7 @@ Start your <a href="Capcode.html#M000010">application</a>.
760
761
  </p>
761
762
  <p>
762
763
  Options : see <a
763
- href="Capcode/Configuration.html#M000023">Capcode::Configuration.set</a>
764
+ href="Capcode/Configuration.html#M000024">Capcode::Configuration.set</a>
764
765
  </p>
765
766
  <p>
766
767
  Options <a href="Capcode.html#M000012">set</a> here replace the ones <a
@@ -770,131 +771,131 @@ href="Capcode.html#M000012">set</a> globally
770
771
  onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
771
772
  <div class="method-source-code" id="M000011-source">
772
773
  <pre>
773
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 672</span>
774
- 672: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
775
- 673: <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>)
776
- 674:
777
- 675: <span class="ruby-comment cmt"># Parse options</span>
778
- 676: <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>
779
- 677: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
780
- 678: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
781
- 679: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
782
- 680:
783
- 681: <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> ) {
784
- 682: <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>
785
- 683: }
786
- 684: <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>
787
- 685: <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>
788
- 686: }
789
- 687: <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>
790
- 688: <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>
791
- 689: }
792
- 690: <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>
793
- 691: <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>
794
- 692: }
795
- 693: <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>
796
- 694: <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>
797
- 695: }
798
- 696: <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>
799
- 697: <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>
800
- 698: }
801
- 699:
802
- 700: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
803
- 701: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
804
- 702:
805
- 703: <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>
806
- 704: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
807
- 705: <span class="ruby-identifier">exit</span>
808
- 706: <span class="ruby-keyword kw">end</span>
809
- 707: <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>
810
- 708: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
811
- 709: <span class="ruby-identifier">exit</span>
812
- 710: <span class="ruby-keyword kw">end</span>
813
- 711: <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>
814
- 712: <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>
815
- 713: <span class="ruby-keyword kw">end</span>
816
- 714: <span class="ruby-keyword kw">end</span>
817
- 715:
818
- 716: <span class="ruby-keyword kw">begin</span>
819
- 717: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
820
- 718: <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>
821
- 719: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
822
- 720: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
823
- 721: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
824
- 722: <span class="ruby-keyword kw">end</span>
825
- 723:
826
- 724: <span class="ruby-comment cmt"># Run in the Working directory</span>
827
- 725: <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>)
828
- 726: <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>
829
- 727:
830
- 728: <span class="ruby-comment cmt"># Check that mongrel exists </span>
831
- 729: <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>
832
- 730: <span class="ruby-keyword kw">begin</span>
833
- 731: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
834
- 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">:server</span>, <span class="ruby-identifier">:mongrel</span>
835
- 733: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
836
- 734: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
837
- 735: <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>
838
- 736: <span class="ruby-keyword kw">end</span>
839
- 737: <span class="ruby-keyword kw">end</span>
840
- 738:
841
- 739: <span class="ruby-comment cmt"># From rackup !!!</span>
842
- 740: <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>)
843
- 741: <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>
844
- 742: <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>
845
- 743: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
846
- 744: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
847
- 745: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
848
- 746: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
849
- 747: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
850
- 748: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
851
- 749: <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>
852
- 750: <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>
853
- 751: <span class="ruby-keyword kw">else</span>
854
- 752: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
855
- 753: <span class="ruby-keyword kw">end</span>
856
- 754: <span class="ruby-keyword kw">else</span>
857
- 755: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
858
- 756: <span class="ruby-keyword kw">end</span>
859
- 757:
860
- 758: <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>) }
861
- 759: <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>)) }
862
- 760: <span class="ruby-keyword kw">end</span>
863
- 761:
864
- 762: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
865
- 763: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
866
- 764: <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> ) }
867
- 765: <span class="ruby-keyword kw">else</span>
868
- 766: <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>)
869
- 767: <span class="ruby-keyword kw">end</span>
870
- 768: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>)) )
871
- 769:
872
- 770: <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>)
873
- 771: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
874
- 772: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
875
- 773: <span class="ruby-identifier">exit</span>
876
- 774: <span class="ruby-keyword kw">end</span>
877
- 775:
878
- 776: <span class="ruby-comment cmt"># Start server</span>
879
- 777: <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>
880
- 778: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
881
- 779: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
882
- 780: <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>
883
- 781: <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> }
884
- 782: }
885
- 783: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
886
- 784: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
887
- 785: <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>
888
- 786: <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> }
889
- 787: }
890
- 788: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;thin&quot;</span>
891
- 789: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
892
- 790: <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>
893
- 791: <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> }
894
- 792: }
895
- 793: <span class="ruby-keyword kw">end</span>
896
- 794: <span class="ruby-keyword kw">end</span>
897
- 795: <span class="ruby-keyword kw">end</span>
774
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 673</span>
775
+ 673: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
776
+ 674: <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>)
777
+ 675:
778
+ 676: <span class="ruby-comment cmt"># Parse options</span>
779
+ 677: <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>
780
+ 678: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
781
+ 679: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
782
+ 680: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
783
+ 681:
784
+ 682: <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> ) {
785
+ 683: <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>
786
+ 684: }
787
+ 685: <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>
788
+ 686: <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>
789
+ 687: }
790
+ 688: <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>
791
+ 689: <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>
792
+ 690: }
793
+ 691: <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>
794
+ 692: <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>
795
+ 693: }
796
+ 694: <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>
797
+ 695: <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>
798
+ 696: }
799
+ 697: <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>
800
+ 698: <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>
801
+ 699: }
802
+ 700:
803
+ 701: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
804
+ 702: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
805
+ 703:
806
+ 704: <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>
807
+ 705: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
808
+ 706: <span class="ruby-identifier">exit</span>
809
+ 707: <span class="ruby-keyword kw">end</span>
810
+ 708: <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>
811
+ 709: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
812
+ 710: <span class="ruby-identifier">exit</span>
813
+ 711: <span class="ruby-keyword kw">end</span>
814
+ 712: <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>
815
+ 713: <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>
816
+ 714: <span class="ruby-keyword kw">end</span>
817
+ 715: <span class="ruby-keyword kw">end</span>
818
+ 716:
819
+ 717: <span class="ruby-keyword kw">begin</span>
820
+ 718: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
821
+ 719: <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>
822
+ 720: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
823
+ 721: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
824
+ 722: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
825
+ 723: <span class="ruby-keyword kw">end</span>
826
+ 724:
827
+ 725: <span class="ruby-comment cmt"># Run in the Working directory</span>
828
+ 726: <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>)
829
+ 727: <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>
830
+ 728:
831
+ 729: <span class="ruby-comment cmt"># Check that mongrel exists </span>
832
+ 730: <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>
833
+ 731: <span class="ruby-keyword kw">begin</span>
834
+ 732: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
835
+ 733: <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>
836
+ 734: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
837
+ 735: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
838
+ 736: <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>
839
+ 737: <span class="ruby-keyword kw">end</span>
840
+ 738: <span class="ruby-keyword kw">end</span>
841
+ 739:
842
+ 740: <span class="ruby-comment cmt"># From rackup !!!</span>
843
+ 741: <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>)
844
+ 742: <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>
845
+ 743: <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>
846
+ 744: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
847
+ 745: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
848
+ 746: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
849
+ 747: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
850
+ 748: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
851
+ 749: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
852
+ 750: <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>
853
+ 751: <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>
854
+ 752: <span class="ruby-keyword kw">else</span>
855
+ 753: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
856
+ 754: <span class="ruby-keyword kw">end</span>
857
+ 755: <span class="ruby-keyword kw">else</span>
858
+ 756: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
859
+ 757: <span class="ruby-keyword kw">end</span>
860
+ 758:
861
+ 759: <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>) }
862
+ 760: <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>)) }
863
+ 761: <span class="ruby-keyword kw">end</span>
864
+ 762:
865
+ 763: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
866
+ 764: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
867
+ 765: <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> ) }
868
+ 766: <span class="ruby-keyword kw">else</span>
869
+ 767: <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>)
870
+ 768: <span class="ruby-keyword kw">end</span>
871
+ 769: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>)) )
872
+ 770:
873
+ 771: <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>)
874
+ 772: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
875
+ 773: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
876
+ 774: <span class="ruby-identifier">exit</span>
877
+ 775: <span class="ruby-keyword kw">end</span>
878
+ 776:
879
+ 777: <span class="ruby-comment cmt"># Start server</span>
880
+ 778: <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>
881
+ 779: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
882
+ 780: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
883
+ 781: <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>
884
+ 782: <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> }
885
+ 783: }
886
+ 784: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
887
+ 785: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
888
+ 786: <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>
889
+ 787: <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> }
890
+ 788: }
891
+ 789: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;thin&quot;</span>
892
+ 790: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
893
+ 791: <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>
894
+ 792: <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> }
895
+ 793: }
896
+ 794: <span class="ruby-keyword kw">end</span>
897
+ 795: <span class="ruby-keyword kw">end</span>
898
+ 796: <span class="ruby-keyword kw">end</span>
898
899
  </pre>
899
900
  </div>
900
901
  </div>
@@ -86,9 +86,10 @@
86
86
  <h3 class="section-bar">Methods</h3>
87
87
 
88
88
  <div class="name-list">
89
- <a href="#M000024">get</a>&nbsp;&nbsp;
90
- <a href="#M000025">options</a>&nbsp;&nbsp;
91
- <a href="#M000023">set</a>&nbsp;&nbsp;
89
+ <a href="#M000025">get</a>&nbsp;&nbsp;
90
+ <a href="#M000026">options</a>&nbsp;&nbsp;
91
+ <a href="#M000023">print_debug</a>&nbsp;&nbsp;
92
+ <a href="#M000024">set</a>&nbsp;&nbsp;
92
93
  </div>
93
94
  </div>
94
95
 
@@ -110,51 +111,51 @@
110
111
  <div id="methods">
111
112
  <h3 class="section-bar">Public Class methods</h3>
112
113
 
113
- <div id="method-M000024" class="method-detail">
114
- <a name="M000024"></a>
114
+ <div id="method-M000025" class="method-detail">
115
+ <a name="M000025"></a>
115
116
 
116
117
  <div class="method-heading">
117
- <a href="#M000024" class="method-signature">
118
+ <a href="#M000025" class="method-signature">
118
119
  <span class="method-name">get</span><span class="method-args">( key = nil )</span>
119
120
  </a>
120
121
  </div>
121
122
 
122
123
  <div class="method-description">
123
124
  <p><a class="source-toggle" href="#"
124
- onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
125
- <div class="method-source-code" id="M000024-source">
125
+ onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
126
+ <div class="method-source-code" id="M000025-source">
126
127
  <pre>
127
- <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 61</span>
128
- 61: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get</span>( <span class="ruby-identifier">key</span> = <span class="ruby-keyword kw">nil</span> )
129
- 62: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">nil?</span>
130
- 63: <span class="ruby-identifier">config</span>
131
- 64: <span class="ruby-keyword kw">else</span>
132
- 65: <span class="ruby-identifier">config</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">nil</span>
133
- 66: <span class="ruby-keyword kw">end</span>
134
- 67: <span class="ruby-keyword kw">end</span>
128
+ <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 67</span>
129
+ 67: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get</span>( <span class="ruby-identifier">key</span> = <span class="ruby-keyword kw">nil</span> )
130
+ 68: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">nil?</span>
131
+ 69: <span class="ruby-identifier">config</span>
132
+ 70: <span class="ruby-keyword kw">else</span>
133
+ 71: <span class="ruby-identifier">config</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">nil</span>
134
+ 72: <span class="ruby-keyword kw">end</span>
135
+ 73: <span class="ruby-keyword kw">end</span>
135
136
  </pre>
136
137
  </div>
137
138
  </div>
138
139
  </div>
139
140
 
140
- <div id="method-M000025" class="method-detail">
141
- <a name="M000025"></a>
141
+ <div id="method-M000026" class="method-detail">
142
+ <a name="M000026"></a>
142
143
 
143
144
  <div class="method-heading">
144
- <a href="#M000025" class="method-signature">
145
+ <a href="#M000026" class="method-signature">
145
146
  <span class="method-name">options</span><span class="method-args">()</span>
146
147
  </a>
147
148
  </div>
148
149
 
149
150
  <div class="method-description">
150
151
  <p><a class="source-toggle" href="#"
151
- onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
152
- <div class="method-source-code" id="M000025-source">
152
+ onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
153
+ <div class="method-source-code" id="M000026-source">
153
154
  <pre>
154
- <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 69</span>
155
- 69: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options</span>
156
- 70: <span class="ruby-ivar">@options</span> <span class="ruby-operator">||=</span> {}
157
- 71: <span class="ruby-keyword kw">end</span>
155
+ <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 75</span>
156
+ 75: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options</span>
157
+ 76: <span class="ruby-ivar">@options</span> <span class="ruby-operator">||=</span> {}
158
+ 77: <span class="ruby-keyword kw">end</span>
158
159
  </pre>
159
160
  </div>
160
161
  </div>
@@ -165,13 +166,38 @@
165
166
 
166
167
  <div class="method-heading">
167
168
  <a href="#M000023" class="method-signature">
169
+ <span class="method-name">print_debug</span><span class="method-args">()</span>
170
+ </a>
171
+ </div>
172
+
173
+ <div class="method-description">
174
+ <p><a class="source-toggle" href="#"
175
+ onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
176
+ <div class="method-source-code" id="M000023-source">
177
+ <pre>
178
+ <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 28</span>
179
+ 28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_debug</span>
180
+ 29: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">config</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>
181
+ 30: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** [CONFIG] : #{k} = #{v}&quot;</span>
182
+ 31: <span class="ruby-keyword kw">end</span>
183
+ 32: <span class="ruby-keyword kw">end</span>
184
+ </pre>
185
+ </div>
186
+ </div>
187
+ </div>
188
+
189
+ <div id="method-M000024" class="method-detail">
190
+ <a name="M000024"></a>
191
+
192
+ <div class="method-heading">
193
+ <a href="#M000024" class="method-signature">
168
194
  <span class="method-name">set</span><span class="method-args">( key, value, opts = {} )</span>
169
195
  </a>
170
196
  </div>
171
197
 
172
198
  <div class="method-description">
173
199
  <p>
174
- Set global configuration <a href="Configuration.html#M000025">options</a>
200
+ Set global configuration <a href="Configuration.html#M000026">options</a>
175
201
  </p>
176
202
  <p>
177
203
  Options :
@@ -213,12 +239,12 @@ This is also the working directory !
213
239
 
214
240
  </li>
215
241
  <li><tt>:auth</tt> = HTTP Basic Authentication <a
216
- href="Configuration.html#M000025">options</a>
242
+ href="Configuration.html#M000026">options</a>
217
243
 
218
244
  </li>
219
245
  </ul>
220
246
  <p>
221
- It can exist specifics <a href="Configuration.html#M000025">options</a>
247
+ It can exist specifics <a href="Configuration.html#M000026">options</a>
222
248
  depending on a renderer, a helper, &#8230;
223
249
  </p>
224
250
  <p>
@@ -231,18 +257,18 @@ Example :
231
257
  end
232
258
  </pre>
233
259
  <p><a class="source-toggle" href="#"
234
- onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
235
- <div class="method-source-code" id="M000023-source">
260
+ onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
261
+ <div class="method-source-code" id="M000024-source">
236
262
  <pre>
237
- <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 52</span>
238
- 52: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set</span>( <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">opts</span> = {} )
239
- 53: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Hash</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">value</span>
240
- 54: <span class="ruby-identifier">opts</span> = <span class="ruby-identifier">value</span>
241
- 55: <span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>
242
- 56: <span class="ruby-keyword kw">end</span>
243
- 57: <span class="ruby-identifier">config</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
244
- 58: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">opts</span>
245
- 59: <span class="ruby-keyword kw">end</span>
263
+ <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 58</span>
264
+ 58: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set</span>( <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">opts</span> = {} )
265
+ 59: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Hash</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">value</span>
266
+ 60: <span class="ruby-identifier">opts</span> = <span class="ruby-identifier">value</span>
267
+ 61: <span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>
268
+ 62: <span class="ruby-keyword kw">end</span>
269
+ 63: <span class="ruby-identifier">config</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
270
+ 64: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">opts</span>
271
+ 65: <span class="ruby-keyword kw">end</span>
246
272
  </pre>
247
273
  </div>
248
274
  </div>
@@ -1 +1 @@
1
- Fri, 28 May 2010 11:19:04 +0200
1
+ Tue, 01 Jun 2010 20:13:22 +0200
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Fri May 28 11:17:27 +0200 2010</td>
59
+ <td>Tue Jun 01 18:08:07 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -91,6 +91,15 @@ href="http://www.algorithmique.net/capcode">www.algorithmique.net/capcode</a>/
91
91
  <a href="../classes/Capcode.html">Capcode</a> is a web microframework
92
92
  </p>
93
93
  <h2>FEATURES/PROBLEMS:</h2>
94
+ <h3>0.9.6</h3>
95
+ <ul>
96
+ <li>More debug trace
97
+
98
+ </li>
99
+ <li>Bug correction in the custom version of Rack::URLmap
100
+
101
+ </li>
102
+ </ul>
94
103
  <h3>0.9.5</h3>
95
104
  <ul>
96
105
  <li>Major bug correction
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Jan 05 17:04:58 +0100 2010</td>
59
+ <td>Fri May 28 11:59:09 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Fri May 28 11:15:55 +0200 2010</td>
59
+ <td>Tue Jun 01 18:02:24 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -28,21 +28,22 @@
28
28
  <a href="classes/Capcode.html#M000013">before_filter (Capcode)</a><br />
29
29
  <a href="classes/Capcode/Helpers.html#M000020">content_for (Capcode::Helpers)</a><br />
30
30
  <a href="classes/Capcode.html#M000003">env (Capcode)</a><br />
31
- <a href="classes/Capcode/Configuration.html#M000024">get (Capcode::Configuration)</a><br />
31
+ <a href="classes/Capcode/Configuration.html#M000025">get (Capcode::Configuration)</a><br />
32
32
  <a href="classes/Capcode.html#M000009">http_authentication (Capcode)</a><br />
33
33
  <a href="classes/Capcode/Helpers/Authorization.html#M000022">http_authentication (Capcode::Helpers::Authorization)</a><br />
34
34
  <a href="classes/Capcode/Helpers.html#M000017">json (Capcode::Helpers)</a><br />
35
35
  <a href="classes/Capcode.html#M000007">map (Capcode)</a><br />
36
- <a href="classes/Capcode/Configuration.html#M000025">options (Capcode::Configuration)</a><br />
36
+ <a href="classes/Capcode/Configuration.html#M000026">options (Capcode::Configuration)</a><br />
37
37
  <a href="classes/Capcode.html#M000002">params (Capcode)</a><br />
38
+ <a href="classes/Capcode/Configuration.html#M000023">print_debug (Capcode::Configuration)</a><br />
38
39
  <a href="classes/Capcode/Helpers.html#M000018">redirect (Capcode::Helpers)</a><br />
39
40
  <a href="classes/Capcode/Helpers.html#M000016">render (Capcode::Helpers)</a><br />
40
41
  <a href="classes/Capcode.html#M000005">request (Capcode)</a><br />
41
42
  <a href="classes/Capcode.html#M000006">response (Capcode)</a><br />
42
43
  <a href="classes/Capcode.html#M000011">run (Capcode)</a><br />
43
44
  <a href="classes/Capcode.html#M000004">session (Capcode)</a><br />
45
+ <a href="classes/Capcode/Configuration.html#M000024">set (Capcode::Configuration)</a><br />
44
46
  <a href="classes/Capcode.html#M000012">set (Capcode)</a><br />
45
- <a href="classes/Capcode/Configuration.html#M000023">set (Capcode::Configuration)</a><br />
46
47
  <a href="classes/Capcode/Helpers.html#M000021">static (Capcode::Helpers)</a><br />
47
48
  <a href="classes/Capcode.html#M000008">use (Capcode)</a><br />
48
49
  </div>
@@ -589,6 +589,7 @@ module Capcode
589
589
  # Options set here replace the ones set globally
590
590
  def application( args = {} )
591
591
  Capcode::Configuration.configuration(args)
592
+ Capcode::Configuration.print_debug if Capcode::Configuration.get(:verbose)
592
593
 
593
594
  Capcode.constants.clone.delete_if {|k|
594
595
  not( Capcode.const_get(k).to_s =~ /Capcode/ ) or [
@@ -25,6 +25,12 @@ module Capcode
25
25
  @configuration ||= {}
26
26
  end
27
27
 
28
+ def print_debug
29
+ Capcode::Configuration.config.each do |k, v|
30
+ puts "** [CONFIG] : #{k} = #{v}"
31
+ end
32
+ end
33
+
28
34
  # Set global configuration options
29
35
  #
30
36
  # Options :
@@ -46,10 +46,19 @@ module Capcode
46
46
  next unless path =~ match && rest = $1
47
47
  next unless rest.empty? || rest[0] == ?/
48
48
 
49
- return app.new.call(
50
- env.merge(
51
- 'SCRIPT_NAME' => (script_name + location),
52
- 'PATH_INFO' => rest))
49
+ # ----------------- CHANGE IS HERE --------------------
50
+ if app.kind_of?(Class)
51
+ return app.new.call(
52
+ env.merge(
53
+ 'SCRIPT_NAME' => (script_name + location),
54
+ 'PATH_INFO' => rest))
55
+ else
56
+ return app.call(
57
+ env.merge(
58
+ 'SCRIPT_NAME' => (script_name + location),
59
+ 'PATH_INFO' => rest))
60
+ end
61
+ # ----------------- CHANGE IS HERE --------------------
53
62
  }
54
63
  [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path}"]]
55
64
  end
@@ -1,3 +1,3 @@
1
1
  module Capcode
2
- CAPCOD_VERION="0.9.5"
2
+ CAPCOD_VERION="0.9.6"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Capcode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 5
10
- version: 0.9.5
9
+ - 6
10
+ version: 0.9.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Gr\xC3\xA9goire Lejeune"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-28 00:00:00 +02:00
18
+ date: 2010-06-01 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency