Capcode 0.8.9 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/README.rdoc +13 -1
  2. data/doc/rdoc/classes/Capcode.html +410 -545
  3. data/doc/rdoc/classes/Capcode/Configuration.html +263 -0
  4. data/doc/rdoc/classes/Capcode/Helpers.html +154 -345
  5. data/doc/rdoc/classes/Capcode/Helpers/Authorization.html +6 -6
  6. data/doc/rdoc/created.rid +1 -1
  7. data/doc/rdoc/files/README_rdoc.html +42 -2
  8. data/doc/rdoc/files/lib/capcode/configuration_rb.html +1 -1
  9. data/doc/rdoc/files/lib/capcode/render/text_rb.html +1 -1
  10. data/doc/rdoc/files/lib/capcode_rb.html +14 -1
  11. data/doc/rdoc/fr_class_index.html +1 -1
  12. data/doc/rdoc/fr_file_index.html +0 -13
  13. data/doc/rdoc/fr_method_index.html +12 -14
  14. data/examples/render-image.rb +1 -1
  15. data/examples/render-text.rb +4 -1
  16. data/examples/rest.rb +1 -0
  17. data/examples/sample.rb +5 -3
  18. data/examples/upload.rb +1 -0
  19. data/lib/capcode.rb +45 -61
  20. data/lib/capcode/configuration.rb +69 -34
  21. data/lib/capcode/render/text.rb +1 -1
  22. data/lib/capcode/version.rb +1 -1
  23. metadata +31 -106
  24. data/doc/rdoc/classes/Capcode/Mab.html +0 -118
  25. data/doc/rdoc/files/lib/capcode/render/binary_rb.html +0 -101
  26. data/doc/rdoc/files/lib/capcode/render/email_rb.html +0 -108
  27. data/doc/rdoc/files/lib/capcode/render/erb_rb.html +0 -108
  28. data/doc/rdoc/files/lib/capcode/render/haml_rb.html +0 -108
  29. data/doc/rdoc/files/lib/capcode/render/json_rb.html +0 -108
  30. data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +0 -108
  31. data/doc/rdoc/files/lib/capcode/render/mustache_rb.html +0 -108
  32. data/doc/rdoc/files/lib/capcode/render/none_rb.html +0 -101
  33. data/doc/rdoc/files/lib/capcode/render/redirect_rb.html +0 -101
  34. data/doc/rdoc/files/lib/capcode/render/sass_rb.html +0 -108
  35. data/doc/rdoc/files/lib/capcode/render/static_rb.html +0 -101
  36. data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +0 -124
  37. data/doc/rdoc/files/lib/capcode/render/xml_rb.html +0 -101
  38. data/examples/auth-webdav.rb +0 -29
  39. data/examples/blog-ar.rb +0 -81
  40. data/examples/blog-ar.yml +0 -3
  41. data/examples/blog-couchdb-run.rb +0 -10
  42. data/examples/blog-couchdb.rb +0 -314
  43. data/examples/blog-couchdb.ru +0 -12
  44. data/examples/blog-couchdb.yml +0 -2
  45. data/examples/blog-dm.rb +0 -63
  46. data/examples/blog-dm.yml +0 -2
  47. data/examples/blog-mongodb-run.rb +0 -10
  48. data/examples/blog-mongodb.rb +0 -304
  49. data/examples/blog-mongodb.yml +0 -3
  50. data/examples/blog-sq.rb +0 -82
  51. data/examples/blog-sq.yml +0 -3
  52. data/examples/mail/mail_html.rhtml +0 -1
  53. data/examples/mail/mail_text.rhtml +0 -1
  54. data/examples/mail/ok.rhtml +0 -1
  55. data/examples/mail/rubyfr.png +0 -0
  56. data/examples/mustache/with_class.mustache +0 -8
  57. data/examples/mustache/without_class.mustache +0 -1
  58. data/examples/render-binary.rb +0 -46
  59. data/examples/render-email.rb +0 -68
  60. data/examples/render-erb.rb +0 -19
  61. data/examples/render-haml_sass.rb +0 -26
  62. data/examples/render-json.rb +0 -13
  63. data/examples/render-markaby.rb +0 -29
  64. data/examples/render-mustache.rb +0 -30
  65. data/examples/render-redirect.rb +0 -19
  66. data/examples/render-static.rb +0 -21
  67. data/examples/render-static.ru +0 -19
  68. data/examples/render-use.rb +0 -32
  69. data/examples/render-webdav.rb +0 -26
  70. data/examples/render-xml.rb +0 -24
  71. data/examples/rss.rb +0 -48
  72. data/examples/static/coderay.css +0 -131
  73. data/examples/static/index.html +0 -24
  74. data/examples/test/index.html +0 -1
  75. data/lib/capcode/base/ar.rb +0 -54
  76. data/lib/capcode/base/couchdb.rb +0 -23
  77. data/lib/capcode/base/dm.rb +0 -33
  78. data/lib/capcode/base/mongodb.rb +0 -27
  79. data/lib/capcode/base/sq.rb +0 -58
  80. data/lib/capcode/render/binary.rb +0 -8
  81. data/lib/capcode/render/email.rb +0 -73
  82. data/lib/capcode/render/erb.rb +0 -59
  83. data/lib/capcode/render/haml.rb +0 -60
  84. data/lib/capcode/render/json.rb +0 -14
  85. data/lib/capcode/render/markaby.rb +0 -38
  86. data/lib/capcode/render/mustache.rb +0 -37
  87. data/lib/capcode/render/none.rb +0 -7
  88. data/lib/capcode/render/redirect.rb +0 -7
  89. data/lib/capcode/render/sass.rb +0 -48
  90. data/lib/capcode/render/static.rb +0 -14
  91. data/lib/capcode/render/webdav.rb +0 -49
  92. data/lib/capcode/render/xml.rb +0 -119
@@ -12,6 +12,18 @@ Capcode is a web microframework
12
12
 
13
13
  == FEATURES/PROBLEMS:
14
14
 
15
+ === 0.9.0
16
+
17
+ * <b>IMPORTANT</b>
18
+ * THIS VERSION IS A MAJOR ENHANCEMENT : YOU MUST UNINSTALL ALL PREVIOUS VERSIONS !!!
19
+ gem uninstall Capode --version '< 0.9.0'
20
+ * Renderers and database accessors have been extracted and are now in the {plugins repository}[http://github.com/glejeune/Capcode.more]. Each plugin is a gem that's can be installed separately.
21
+ * <b>Important, but less!</b>
22
+ * Add {Coffee-Script}[http://jashkenas.github.com/coffee-script/] renderer
23
+ * Update renderers options
24
+ * Rewrite configuration
25
+ * Bug corrections in all DB modules
26
+
15
27
  === 0.8.9
16
28
  * Add Thin support
17
29
  * Add MongoDB support
@@ -295,7 +307,7 @@ See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for co
295
307
  # !!! Render file from /Users/greg/temp !!!
296
308
  class WebDav < Route '/temp'
297
309
  def get
298
- render :webdav => "/Users/greg"
310
+ render :webdav => "/Users/greg/temp"
299
311
  end
300
312
 
301
313
  def method_missing(id, *a, &b)
@@ -66,62 +66,10 @@
66
66
  <a href="../files/lib/capcode/configuration_rb.html">
67
67
  lib/capcode/configuration.rb
68
68
  </a>
69
- <br />
70
- <a href="../files/lib/capcode/render/binary_rb.html">
71
- lib/capcode/render/binary.rb
72
- </a>
73
- <br />
74
- <a href="../files/lib/capcode/render/email_rb.html">
75
- lib/capcode/render/email.rb
76
- </a>
77
- <br />
78
- <a href="../files/lib/capcode/render/erb_rb.html">
79
- lib/capcode/render/erb.rb
80
- </a>
81
- <br />
82
- <a href="../files/lib/capcode/render/haml_rb.html">
83
- lib/capcode/render/haml.rb
84
- </a>
85
- <br />
86
- <a href="../files/lib/capcode/render/json_rb.html">
87
- lib/capcode/render/json.rb
88
- </a>
89
- <br />
90
- <a href="../files/lib/capcode/render/markaby_rb.html">
91
- lib/capcode/render/markaby.rb
92
- </a>
93
- <br />
94
- <a href="../files/lib/capcode/render/mustache_rb.html">
95
- lib/capcode/render/mustache.rb
96
- </a>
97
- <br />
98
- <a href="../files/lib/capcode/render/none_rb.html">
99
- lib/capcode/render/none.rb
100
- </a>
101
- <br />
102
- <a href="../files/lib/capcode/render/redirect_rb.html">
103
- lib/capcode/render/redirect.rb
104
- </a>
105
- <br />
106
- <a href="../files/lib/capcode/render/sass_rb.html">
107
- lib/capcode/render/sass.rb
108
- </a>
109
- <br />
110
- <a href="../files/lib/capcode/render/static_rb.html">
111
- lib/capcode/render/static.rb
112
- </a>
113
69
  <br />
114
70
  <a href="../files/lib/capcode/render/text_rb.html">
115
71
  lib/capcode/render/text.rb
116
72
  </a>
117
- <br />
118
- <a href="../files/lib/capcode/render/webdav_rb.html">
119
- lib/capcode/render/webdav.rb
120
- </a>
121
- <br />
122
- <a href="../files/lib/capcode/render/xml_rb.html">
123
- lib/capcode/render/xml.rb
124
- </a>
125
73
  <br />
126
74
  <a href="../files/lib/capcode/helpers/auth_rb.html">
127
75
  lib/capcode/helpers/auth.rb
@@ -150,7 +98,6 @@
150
98
  <div class="name-list">
151
99
  <a href="#M000001">Route</a>&nbsp;&nbsp;
152
100
  <a href="#M000010">application</a>&nbsp;&nbsp;
153
- <a href="#M000013">config</a>&nbsp;&nbsp;
154
101
  <a href="#M000003">env</a>&nbsp;&nbsp;
155
102
  <a href="#M000009">http_authentication</a>&nbsp;&nbsp;
156
103
  <a href="#M000007">map</a>&nbsp;&nbsp;
@@ -187,8 +134,8 @@
187
134
  Module <a href="Capcode/Resource.html" class="link">Capcode::Resource</a><br />
188
135
  Module <a href="Capcode/Views.html" class="link">Capcode::Views</a><br />
189
136
  Class <a href="Capcode/Base.html" class="link">Capcode::Base</a><br />
137
+ Class <a href="Capcode/Configuration.html" class="link">Capcode::Configuration</a><br />
190
138
  Class <a href="Capcode/HTTPError.html" class="link">Capcode::HTTPError</a><br />
191
- Class <a href="Capcode/Mab.html" class="link">Capcode::Mab</a><br />
192
139
 
193
140
  </div>
194
141
 
@@ -255,169 +202,169 @@ If the regexp in the route does not match, all arguments will be
255
202
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
256
203
  <div class="method-source-code" id="M000001-source">
257
204
  <pre>
258
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 305</span>
259
- 305: <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>
260
- 306: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
261
- 307: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
262
- 308: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/</span>
263
- 309: <span class="ruby-comment cmt"># # =&gt; [ {'/hello/world' =&gt; '([^\/]*)/id(\d*)', '/hello' =&gt; '(.*)'}, </span>
264
- 310: <span class="ruby-comment cmt"># 2, </span>
265
- 311: <span class="ruby-comment cmt"># &lt;Capcode::Klass&gt;, </span>
266
- 312: <span class="ruby-comment cmt"># {:agent =&gt; /Songbird (\d\.\d)[\d\/]*?/} ]</span>
267
- 313: <span class="ruby-identifier">hash_of_routes</span> = {}
268
- 314: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
269
- 315: <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>
270
- 316: <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>
271
- 317: <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> )
272
- 318: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
273
- 319: <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>)
274
- 320: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
275
- 321: <span class="ruby-keyword kw">else</span>
276
- 322: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
277
- 323: <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>
278
- 324: <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>)
279
- 325: <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>]
280
- 326: <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>
281
- 327: <span class="ruby-keyword kw">end</span>
282
- 328: <span class="ruby-keyword kw">else</span>
283
- 329: <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>
284
- 330: <span class="ruby-keyword kw">end</span>
285
- 331: <span class="ruby-keyword kw">end</span>
286
- 332: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
287
- 333: }
288
- 334:
289
- 335: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
290
- 336: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
291
- 337: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
292
- 338: <span class="ruby-keyword kw">end</span>
293
- 339:
294
- 340: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
295
- 341: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
296
- 342: <span class="ruby-ivar">@env</span>
297
- 343: <span class="ruby-keyword kw">end</span>
298
- 344:
299
- 345: <span class="ruby-comment cmt"># Session hash</span>
300
- 346: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
301
- 347: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
302
- 348: <span class="ruby-keyword kw">end</span>
303
- 349:
304
- 350: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
305
- 351: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
306
- 352: <span class="ruby-ivar">@request</span>
307
- 353: <span class="ruby-keyword kw">end</span>
308
- 354:
309
- 355: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
310
- 356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
311
- 357: <span class="ruby-ivar">@response</span>
312
- 358: <span class="ruby-keyword kw">end</span>
313
- 359:
314
- 360: <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>
315
- 361: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
316
- 362: <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>
317
- 363: <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>)
318
- 364:
319
- 365: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
320
- 366: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
321
- 367: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
322
- 368: <span class="ruby-comment cmt"># __run = true</span>
323
- 369: <span class="ruby-comment cmt"># if f[:only]</span>
324
- 370: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
325
- 371: <span class="ruby-comment cmt"># end</span>
326
- 372: <span class="ruby-comment cmt"># if f[:except]</span>
327
- 373: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
328
- 374: <span class="ruby-comment cmt"># end</span>
329
- 375: <span class="ruby-comment cmt"># </span>
330
- 376: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
331
- 377: <span class="ruby-comment cmt"># puts &quot;call #{proc} for #{__k}&quot;</span>
332
- 378: <span class="ruby-comment cmt"># end</span>
333
- 379:
334
- 380: <span class="ruby-comment cmt"># Check authz</span>
335
- 381: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
336
- 382: <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>
337
- 383: <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>
338
- 384: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
339
- 385: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
340
- 386:
341
- 387: <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>
342
- 388: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">&quot;^#{r.gsub(/\/$/, &quot;&quot;)}([/]{1}.*)?$&quot;</span>
343
- 389: <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> )
344
- 390: <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>
345
- 391: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
346
- 392: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
347
- 393: <span class="ruby-keyword kw">end</span>
348
- 394: <span class="ruby-keyword kw">end</span>
349
- 395: <span class="ruby-keyword kw">end</span>
350
- 396: <span class="ruby-keyword kw">end</span>
351
- 397: <span class="ruby-keyword kw">end</span>
352
- 398:
353
- 399: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
354
- 400: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
355
- 401: <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>] ) {
356
- 402: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
357
- 403: }
358
- 404: <span class="ruby-keyword kw">end</span>
359
- 405:
360
- 406: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
361
- 407: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
362
- 408: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
363
- 409:
364
- 410: <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> )
365
- 411: <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>
366
- 412: <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> )
367
- 413: <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>
368
- 414: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
369
- 415: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
370
- 416: <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>
371
- 417: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
372
- 418: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
373
- 419: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
374
- 420: <span class="ruby-keyword kw">end</span>
375
- 421: <span class="ruby-keyword kw">end</span>
376
- 422:
377
- 423: <span class="ruby-keyword kw">end</span>
378
- 424:
379
- 425: <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>]
380
- 426: <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>] )
381
- 427: <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> ) )
382
- 428: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
383
- 429: <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>
384
- 430: <span class="ruby-keyword kw">else</span>
385
- 431: <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> }
386
- 432: <span class="ruby-keyword kw">end</span>
387
- 433:
388
- 434: <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>
389
- 435: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
390
- 436: <span class="ruby-keyword kw">end</span>
391
- 437:
392
- 438: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
393
- 439: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;GET&quot;</span>
394
- 440: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
395
- 441: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
396
- 442: <span class="ruby-identifier">_method</span> = <span class="ruby-identifier">params</span>.<span class="ruby-identifier">delete</span>( <span class="ruby-value str">&quot;_method&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-value str">&quot;post&quot;</span> }
397
- 443: <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> )
398
- 444: <span class="ruby-keyword kw">else</span>
399
- 445: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
400
- 446: <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> )
401
- 447: <span class="ruby-keyword kw">end</span>
402
- 448: }
403
- 449: <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>)
404
- 450: <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>
405
- 451: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
406
- 452: <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>
407
- 453: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
408
- 454: <span class="ruby-keyword kw">end</span>
409
- 455: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[2]</span>
410
- 456: <span class="ruby-keyword kw">else</span>
411
- 457: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
412
- 458: <span class="ruby-keyword kw">end</span>
413
- 459:
414
- 460: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
415
- 461: <span class="ruby-keyword kw">end</span>
416
- 462:
417
- 463: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
418
- 464: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
419
- 465: }
420
- 466: <span class="ruby-keyword kw">end</span>
205
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 306</span>
206
+ 306: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">routes_paths</span>
207
+ 307: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
208
+ 308: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
209
+ 309: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent =&gt; /Songbird (\d\.\d)[\d\/]*?/</span>
210
+ 310: <span class="ruby-comment cmt"># # =&gt; [ {'/hello/world' =&gt; '([^\/]*)/id(\d*)', '/hello' =&gt; '(.*)'}, </span>
211
+ 311: <span class="ruby-comment cmt"># 2, </span>
212
+ 312: <span class="ruby-comment cmt"># &lt;Capcode::Klass&gt;, </span>
213
+ 313: <span class="ruby-comment cmt"># {:agent =&gt; /Songbird (\d\.\d)[\d\/]*?/} ]</span>
214
+ 314: <span class="ruby-identifier">hash_of_routes</span> = {}
215
+ 315: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
216
+ 316: <span class="ruby-identifier">routes_paths</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
217
+ 317: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current_route_path</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">String</span>
218
+ 318: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">current_route_path</span> )
219
+ 319: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
220
+ 320: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">&quot;Route `#{current_route_path}' already defined with regexp `#{hash_of_routes[current_route_path]}' !&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">current_route_path</span>)
221
+ 321: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
222
+ 322: <span class="ruby-keyword kw">else</span>
223
+ 323: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
224
+ 324: <span class="ruby-identifier">_pre</span> = <span class="ruby-value str">&quot;/&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">_pre</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
225
+ 325: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">&quot;Route `#{_pre}' already defined with regexp `#{hash_of_routes[_pre]}' !&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_pre</span>)
226
+ 326: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">_pre</span>] = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]
227
+ 327: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">max_captures_for_routes</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span>
228
+ 328: <span class="ruby-keyword kw">end</span>
229
+ 329: <span class="ruby-keyword kw">else</span>
230
+ 330: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-value str">&quot;Bad route declaration !&quot;</span>, <span class="ruby-identifier">caller</span>
231
+ 331: <span class="ruby-keyword kw">end</span>
232
+ 332: <span class="ruby-keyword kw">end</span>
233
+ 333: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
234
+ 334: }
235
+ 335:
236
+ 336: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
237
+ 337: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
238
+ 338: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
239
+ 339: <span class="ruby-keyword kw">end</span>
240
+ 340:
241
+ 341: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
242
+ 342: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
243
+ 343: <span class="ruby-ivar">@env</span>
244
+ 344: <span class="ruby-keyword kw">end</span>
245
+ 345:
246
+ 346: <span class="ruby-comment cmt"># Session hash</span>
247
+ 347: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
248
+ 348: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
249
+ 349: <span class="ruby-keyword kw">end</span>
250
+ 350:
251
+ 351: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
252
+ 352: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
253
+ 353: <span class="ruby-ivar">@request</span>
254
+ 354: <span class="ruby-keyword kw">end</span>
255
+ 355:
256
+ 356: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
257
+ 357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
258
+ 358: <span class="ruby-ivar">@response</span>
259
+ 359: <span class="ruby-keyword kw">end</span>
260
+ 360:
261
+ 361: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>( <span class="ruby-identifier">e</span> ) <span class="ruby-comment cmt">#:nodoc:</span>
262
+ 362: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
263
+ 363: <span class="ruby-ivar">@response</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Response</span>.<span class="ruby-identifier">new</span>
264
+ 364: <span class="ruby-ivar">@request</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@env</span>)
265
+ 365:
266
+ 366: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
267
+ 367: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
268
+ 368: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
269
+ 369: <span class="ruby-comment cmt"># __run = true</span>
270
+ 370: <span class="ruby-comment cmt"># if f[:only]</span>
271
+ 371: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
272
+ 372: <span class="ruby-comment cmt"># end</span>
273
+ 373: <span class="ruby-comment cmt"># if f[:except]</span>
274
+ 374: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
275
+ 375: <span class="ruby-comment cmt"># end</span>
276
+ 376: <span class="ruby-comment cmt"># </span>
277
+ 377: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
278
+ 378: <span class="ruby-comment cmt"># puts &quot;call #{proc} for #{__k}&quot;</span>
279
+ 379: <span class="ruby-comment cmt"># end</span>
280
+ 380:
281
+ 381: <span class="ruby-comment cmt"># Check authz</span>
282
+ 382: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
283
+ 383: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
284
+ 384: <span class="ruby-identifier">authz_options</span> = <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>[<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>
285
+ 385: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
286
+ 386: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
287
+ 387:
288
+ 388: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span>, <span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
289
+ 389: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">&quot;^#{r.gsub(/\/$/, &quot;&quot;)}([/]{1}.*)?$&quot;</span>
290
+ 390: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">regexp</span>).<span class="ruby-identifier">match</span>( <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span> )
291
+ 391: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">size</span>
292
+ 392: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
293
+ 393: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
294
+ 394: <span class="ruby-keyword kw">end</span>
295
+ 395: <span class="ruby-keyword kw">end</span>
296
+ 396: <span class="ruby-keyword kw">end</span>
297
+ 397: <span class="ruby-keyword kw">end</span>
298
+ 398: <span class="ruby-keyword kw">end</span>
299
+ 399:
300
+ 400: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
301
+ 401: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
302
+ 402: <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:type</span>], <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:realm</span>], <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:realm</span>] ) {
303
+ 403: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
304
+ 404: }
305
+ 405: <span class="ruby-keyword kw">end</span>
306
+ 406:
307
+ 407: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
308
+ 408: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
309
+ 409: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
310
+ 410:
311
+ 411: <span class="ruby-identifier">aPath</span> = <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">&quot;/&quot;</span> )
312
+ 412: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
313
+ 413: <span class="ruby-identifier">xPath</span> = <span class="ruby-identifier">p</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">&quot;/&quot;</span> )
314
+ 414: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">aPath</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
315
+ 415: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
316
+ 416: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
317
+ 417: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">finalNArgs</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">finalNArgs</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">diffNArgs</span>
318
+ 418: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
319
+ 419: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
320
+ 420: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
321
+ 421: <span class="ruby-keyword kw">end</span>
322
+ 422: <span class="ruby-keyword kw">end</span>
323
+ 423:
324
+ 424: <span class="ruby-keyword kw">end</span>
325
+ 425:
326
+ 426: <span class="ruby-identifier">nargs</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">1</span>]
327
+ 427: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>][<span class="ruby-identifier">finalPath</span>] )
328
+ 428: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>( <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>).<span class="ruby-identifier">gsub</span>( <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-node">&quot;^#{finalPath}&quot;</span> ), <span class="ruby-value str">&quot;&quot;</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span> ) )
329
+ 429: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
330
+ 430: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-node">&quot;Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'&quot;</span>
331
+ 431: <span class="ruby-keyword kw">else</span>
332
+ 432: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">x</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)<span class="ruby-operator">?</span><span class="ruby-keyword kw">nil</span><span class="ruby-operator">:</span><span class="ruby-identifier">x</span> }
333
+ 433: <span class="ruby-keyword kw">end</span>
334
+ 434:
335
+ 435: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">nargs</span>
336
+ 436: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
337
+ 437: <span class="ruby-keyword kw">end</span>
338
+ 438:
339
+ 439: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
340
+ 440: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;GET&quot;</span>
341
+ 441: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
342
+ 442: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
343
+ 443: <span class="ruby-identifier">_method</span> = <span class="ruby-identifier">params</span>.<span class="ruby-identifier">delete</span>( <span class="ruby-value str">&quot;_method&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-value str">&quot;post&quot;</span> }
344
+ 444: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
345
+ 445: <span class="ruby-keyword kw">else</span>
346
+ 446: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
347
+ 447: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
348
+ 448: <span class="ruby-keyword kw">end</span>
349
+ 449: }
350
+ 450: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_ary</span>)
351
+ 451: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[0]</span>
352
+ 452: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
353
+ 453: <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
354
+ 454: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
355
+ 455: <span class="ruby-keyword kw">end</span>
356
+ 456: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[2]</span>
357
+ 457: <span class="ruby-keyword kw">else</span>
358
+ 458: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
359
+ 459: <span class="ruby-keyword kw">end</span>
360
+ 460:
361
+ 461: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
362
+ 462: <span class="ruby-keyword kw">end</span>
363
+ 463:
364
+ 464: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
365
+ 465: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
366
+ 466: }
367
+ 467: <span class="ruby-keyword kw">end</span>
421
368
  </pre>
422
369
  </div>
423
370
  </div>
@@ -437,7 +384,8 @@ If the regexp in the route does not match, all arguments will be
437
384
  Return the Rack App.
438
385
  </p>
439
386
  <p>
440
- Options : see <a href="Capcode.html#M000012">Capcode.set</a>
387
+ Options : see <a
388
+ href="Capcode/Configuration.html#M000022">Capcode::Configuration.set</a>
441
389
  </p>
442
390
  <p>
443
391
  Options <a href="Capcode.html#M000012">set</a> here replace the ones <a
@@ -447,94 +395,71 @@ href="Capcode.html#M000012">set</a> globally
447
395
  onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
448
396
  <div class="method-source-code" id="M000010-source">
449
397
  <pre>
450
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 552</span>
451
- 552: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
452
- 553: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
398
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 536</span>
399
+ 536: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
400
+ 537: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
401
+ 538:
402
+ 539: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
403
+ 540: <span class="ruby-keyword kw">begin</span>
404
+ 541: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.public_methods(true).include?( '__urls__' )&quot;</span>
405
+ 542: <span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.__urls__&quot;</span>
406
+ 543: <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
407
+ 544: <span class="ruby-comment cmt">#raise Capcode::RouteError, &quot;Route `#{current_route_path}' already define !&quot;, caller if @@__ROUTES.keys.include?(current_route_path)</span>
408
+ 545: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">&quot;Route `#{current_route_path}' already define !&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">current_route_path</span>)
409
+ 546: <span class="ruby-comment cmt">#@@__ROUTES[current_route_path] = klass.new</span>
410
+ 547: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>
411
+ 548: <span class="ruby-keyword kw">end</span>
412
+ 549: <span class="ruby-keyword kw">end</span>
413
+ 550: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
414
+ 551: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
415
+ 552: <span class="ruby-keyword kw">end</span>
416
+ 553: <span class="ruby-keyword kw">end</span>
453
417
  554:
454
- 555: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
455
- 556: <span class="ruby-keyword kw">begin</span>
456
- 557: <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>
457
- 558: <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>
458
- 559: <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>
459
- 560: <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>
460
- 561: <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>)
461
- 562: <span class="ruby-comment cmt">#@@__ROUTES[current_route_path] = klass.new</span>
462
- 563: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>
463
- 564: <span class="ruby-keyword kw">end</span>
464
- 565: <span class="ruby-keyword kw">end</span>
465
- 566: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
466
- 567: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
467
- 568: <span class="ruby-keyword kw">end</span>
468
- 569: <span class="ruby-keyword kw">end</span>
469
- 570:
470
- 571: <span class="ruby-comment cmt"># Set Static directory</span>
471
- 572: <span class="ruby-comment cmt">#@@__STATIC_DIR = (conf[:static][0].chr == &quot;/&quot;)?conf[:static]:&quot;/&quot;+conf[:static] unless conf[:static].nil?</span>
472
- 573: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span> = (<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">chr</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;/&quot;</span>)<span class="ruby-operator">?</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>]<span class="ruby-operator">:</span><span class="ruby-value str">&quot;/&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
473
- 574:
474
- 575: <span class="ruby-comment cmt"># Initialize Rack App</span>
475
- 576: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;** Map routes.&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
476
- 577: <span class="ruby-comment cmt">#app = Rack::URLMap.new(@@__ROUTES)</span>
477
- 578: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>)
478
- 579: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Initialize static directory (#{conf[:static]})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
479
- 580: <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>(
480
- 581: <span class="ruby-identifier">app</span>,
481
- 582: <span class="ruby-comment cmt">#:urls =&gt; [@@__STATIC_DIR], </span>
482
- 583: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
483
- 584: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>])
484
- 585: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
485
- 586: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;** Initialize session&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
486
- 587: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:session</span>] )
487
- 588: <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>)
488
- 589: <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>)
489
- 590: <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>)
490
- 591: <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>)
491
- 592: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
492
- 593: <span class="ruby-comment cmt"># app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )</span>
493
- 594:
494
- 595: <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>
495
- 596: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
496
- 597: <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-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
497
- 598: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
498
- 599: <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> )
499
- 600: <span class="ruby-keyword kw">else</span>
500
- 601: <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> )
501
- 602: <span class="ruby-keyword kw">end</span>
502
- 603: <span class="ruby-keyword kw">end</span>
503
- 604:
504
- 605: <span class="ruby-comment cmt"># Start database</span>
505
- 606: <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>
506
- 607: <span class="ruby-identifier">db_connect</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:db_config</span>], <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>] )
507
- 608: <span class="ruby-keyword kw">end</span>
508
- 609:
509
- 610: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
510
- 611: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
511
- 612: <span class="ruby-keyword kw">end</span>
512
- 613:
513
- 614: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
514
- 615: <span class="ruby-keyword kw">end</span>
515
- </pre>
516
- </div>
517
- </div>
518
- </div>
519
-
520
- <div id="method-M000013" class="method-detail">
521
- <a name="M000013"></a>
522
-
523
- <div class="method-heading">
524
- <a href="#M000013" class="method-signature">
525
- <span class="method-name">config</span><span class="method-args">()</span>
526
- </a>
527
- </div>
528
-
529
- <div class="method-description">
530
- <p><a class="source-toggle" href="#"
531
- onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
532
- <div class="method-source-code" id="M000013-source">
533
- <pre>
534
- <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 35</span>
535
- 35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>
536
- 36: <span class="ruby-ivar">@configuration</span> <span class="ruby-operator">||=</span> {}
537
- 37: <span class="ruby-keyword kw">end</span>
418
+ 555: <span class="ruby-comment cmt"># Set Static directory</span>
419
+ 556: <span class="ruby-comment cmt">#@@__STATIC_DIR = (conf[:static][0].chr == &quot;/&quot;)?conf[:static]:&quot;/&quot;+conf[:static] unless conf[:static].nil?</span>
420
+ 557: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span> = (<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>)[<span class="ruby-value">0</span>].<span class="ruby-identifier">chr</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;/&quot;</span>)<span class="ruby-operator">?</span><span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>)<span class="ruby-operator">:</span><span class="ruby-value str">&quot;/&quot;</span><span class="ruby-operator">+</span><span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>).<span class="ruby-identifier">nil?</span>
421
+ 558:
422
+ 559: <span class="ruby-comment cmt"># Initialize Rack App</span>
423
+ 560: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;** Map routes.&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
424
+ 561: <span class="ruby-comment cmt">#app = Rack::URLMap.new(@@__ROUTES)</span>
425
+ 562: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>)
426
+ 563: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Initialize static directory (#{Capcode::Configuration.get(:static)})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
427
+ 564: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Static</span>.<span class="ruby-identifier">new</span>(
428
+ 565: <span class="ruby-identifier">app</span>,
429
+ 566: <span class="ruby-comment cmt">#:urls =&gt; [@@__STATIC_DIR], </span>
430
+ 567: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
431
+ 568: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>))
432
+ 569: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>).<span class="ruby-identifier">nil?</span>
433
+ 570: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;** Initialize session&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
434
+ 571: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:session</span>) )
435
+ 572: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
436
+ 573: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
437
+ 574: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
438
+ 575: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ShowExceptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
439
+ 576: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
440
+ 577: <span class="ruby-comment cmt"># app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )</span>
441
+ 578:
442
+ 579: <span class="ruby-identifier">middlewares</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mw</span><span class="ruby-operator">|</span>
443
+ 580: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
444
+ 581: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Load middleware #{middleware}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
445
+ 582: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
446
+ 583: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
447
+ 584: <span class="ruby-keyword kw">else</span>
448
+ 585: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
449
+ 586: <span class="ruby-keyword kw">end</span>
450
+ 587: <span class="ruby-keyword kw">end</span>
451
+ 588:
452
+ 589: <span class="ruby-comment cmt"># Start database</span>
453
+ 590: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">&quot;db_connect&quot;</span>
454
+ 591: <span class="ruby-identifier">db_connect</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:db_config</span>), <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>) )
455
+ 592: <span class="ruby-keyword kw">end</span>
456
+ 593:
457
+ 594: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
458
+ 595: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
459
+ 596: <span class="ruby-keyword kw">end</span>
460
+ 597:
461
+ 598: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
462
+ 599: <span class="ruby-keyword kw">end</span>
538
463
  </pre>
539
464
  </div>
540
465
  </div>
@@ -557,10 +482,10 @@ Hash containing all the environment variables
557
482
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
558
483
  <div class="method-source-code" id="M000003-source">
559
484
  <pre>
560
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 341</span>
561
- 341: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
562
- 342: <span class="ruby-ivar">@env</span>
563
- 343: <span class="ruby-keyword kw">end</span>
485
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 342</span>
486
+ 342: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
487
+ 343: <span class="ruby-ivar">@env</span>
488
+ 344: <span class="ruby-keyword kw">end</span>
564
489
  </pre>
565
490
  </div>
566
491
  </div>
@@ -615,27 +540,27 @@ The block must return a Hash of username =&gt; password like that :
615
540
  onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
616
541
  <div class="method-source-code" id="M000009-source">
617
542
  <pre>
618
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 509</span>
619
- 509: <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> )
620
- 510: <span class="ruby-identifier">options</span> = {
621
- 511: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:basic</span>,
622
- 512: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;Capcode.app&quot;</span>,
623
- 513: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;opaque&quot;</span>,
624
- 514: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/&quot;</span>
625
- 515: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
626
- 516:
627
- 517: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
628
- 518:
629
- 519: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
630
- 520:
631
- 521: <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>
632
- 522: <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>
633
- 523: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
634
- 524: <span class="ruby-keyword kw">end</span>
635
- 525: <span class="ruby-keyword kw">else</span>
636
- 526: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
637
- 527: <span class="ruby-keyword kw">end</span>
638
- 528: <span class="ruby-keyword kw">end</span>
543
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 510</span>
544
+ 510: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
545
+ 511: <span class="ruby-identifier">options</span> = {
546
+ 512: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:basic</span>,
547
+ 513: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;Capcode.app&quot;</span>,
548
+ 514: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;opaque&quot;</span>,
549
+ 515: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/&quot;</span>
550
+ 516: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
551
+ 517:
552
+ 518: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
553
+ 519:
554
+ 520: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
555
+ 521:
556
+ 522: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Array</span>
557
+ 523: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
558
+ 524: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
559
+ 525: <span class="ruby-keyword kw">end</span>
560
+ 526: <span class="ruby-keyword kw">else</span>
561
+ 527: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
562
+ 528: <span class="ruby-keyword kw">end</span>
563
+ 529: <span class="ruby-keyword kw">end</span>
639
564
  </pre>
640
565
  </div>
641
566
  </div>
@@ -664,11 +589,11 @@ Rack or What you want Helper
664
589
  onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
665
590
  <div class="method-source-code" id="M000007-source">
666
591
  <pre>
667
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 473</span>
668
- 473: <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> )
669
- 474: <span class="ruby-comment cmt">#@@__ROUTES[route] = yield</span>
670
- 475: <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>
671
- 476: <span class="ruby-keyword kw">end</span>
592
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 474</span>
593
+ 474: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">route</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
594
+ 475: <span class="ruby-comment cmt">#@@__ROUTES[route] = yield</span>
595
+ 476: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">route</span>] = <span class="ruby-keyword kw">yield</span>
596
+ 477: <span class="ruby-keyword kw">end</span>
672
597
  </pre>
673
598
  </div>
674
599
  </div>
@@ -692,10 +617,10 @@ parameters (GET or POST)
692
617
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
693
618
  <div class="method-source-code" id="M000002-source">
694
619
  <pre>
695
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 336</span>
696
- 336: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
697
- 337: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
698
- 338: <span class="ruby-keyword kw">end</span>
620
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 337</span>
621
+ 337: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
622
+ 338: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
623
+ 339: <span class="ruby-keyword kw">end</span>
699
624
  </pre>
700
625
  </div>
701
626
  </div>
@@ -718,10 +643,10 @@ Return the Rack::Request object
718
643
  onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
719
644
  <div class="method-source-code" id="M000005-source">
720
645
  <pre>
721
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 351</span>
722
- 351: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
723
- 352: <span class="ruby-ivar">@request</span>
724
- 353: <span class="ruby-keyword kw">end</span>
646
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 352</span>
647
+ 352: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
648
+ 353: <span class="ruby-ivar">@request</span>
649
+ 354: <span class="ruby-keyword kw">end</span>
725
650
  </pre>
726
651
  </div>
727
652
  </div>
@@ -744,10 +669,10 @@ Return the Rack::Response object
744
669
  onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
745
670
  <div class="method-source-code" id="M000006-source">
746
671
  <pre>
747
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 356</span>
748
- 356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
749
- 357: <span class="ruby-ivar">@response</span>
750
- 358: <span class="ruby-keyword kw">end</span>
672
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 357</span>
673
+ 357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
674
+ 358: <span class="ruby-ivar">@response</span>
675
+ 359: <span class="ruby-keyword kw">end</span>
751
676
  </pre>
752
677
  </div>
753
678
  </div>
@@ -767,7 +692,8 @@ Return the Rack::Response object
767
692
  Start your <a href="Capcode.html#M000010">application</a>.
768
693
  </p>
769
694
  <p>
770
- Options : see <a href="Capcode.html#M000012">Capcode.set</a>
695
+ Options : see <a
696
+ href="Capcode/Configuration.html#M000022">Capcode::Configuration.set</a>
771
697
  </p>
772
698
  <p>
773
699
  Options <a href="Capcode.html#M000012">set</a> here replace the ones <a
@@ -777,131 +703,131 @@ href="Capcode.html#M000012">set</a> globally
777
703
  onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
778
704
  <div class="method-source-code" id="M000011-source">
779
705
  <pre>
780
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 622</span>
781
- 622: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
782
- 623: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
783
- 624:
784
- 625: <span class="ruby-comment cmt"># Parse options</span>
785
- 626: <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>
786
- 627: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
787
- 628: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
788
- 629: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
789
- 630:
790
- 631: <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> ) {
791
- 632: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>] = <span class="ruby-keyword kw">true</span>
792
- 633: }
793
- 634: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-h&quot;</span>, <span class="ruby-value str">&quot;--host HOSTNAME&quot;</span>, <span class="ruby-node">&quot;Host for web server to bind to (default: #{conf[:host]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
794
- 635: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
795
- 636: }
796
- 637: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-p&quot;</span>, <span class="ruby-value str">&quot;--port NUM&quot;</span>, <span class="ruby-node">&quot;Port for web server (default: #{conf[:port]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
797
- 638: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">p</span>
798
- 639: }
799
- 640: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-d&quot;</span>, <span class="ruby-value str">&quot;--daemonize [true|false]&quot;</span>, <span class="ruby-node">&quot;Daemonize (default: #{conf[:daemonize]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
800
- 641: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span>
801
- 642: }
802
- 643: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-r&quot;</span>, <span class="ruby-value str">&quot;--root PATH&quot;</span>, <span class="ruby-node">&quot;Working directory (default: #{conf[:root]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
803
- 644: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] = <span class="ruby-identifier">w</span>
804
- 645: }
805
- 646: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-s&quot;</span>, <span class="ruby-value str">&quot;--static PATH&quot;</span>, <span class="ruby-node">&quot;Static directory -- relative to the root directory (default: #{conf[:static]})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
806
- 647: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] = <span class="ruby-identifier">r</span>
807
- 648: }
808
- 649:
809
- 650: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
810
- 651: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
811
- 652:
812
- 653: <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>
813
- 654: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
814
- 655: <span class="ruby-identifier">exit</span>
815
- 656: <span class="ruby-keyword kw">end</span>
816
- 657: <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>
817
- 658: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
818
- 659: <span class="ruby-identifier">exit</span>
819
- 660: <span class="ruby-keyword kw">end</span>
820
- 661: <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>
821
- 662: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>] = <span class="ruby-keyword kw">true</span>
822
- 663: <span class="ruby-keyword kw">end</span>
823
- 664: <span class="ruby-keyword kw">end</span>
824
- 665:
825
- 666: <span class="ruby-keyword kw">begin</span>
826
- 667: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
827
- 668: <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>
828
- 669: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
829
- 670: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
830
- 671: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
831
- 672: <span class="ruby-keyword kw">end</span>
832
- 673:
833
- 674: <span class="ruby-comment cmt"># Run in the Working directory</span>
834
- 675: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Go on root directory (#{File.expand_path(conf[:root])})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
835
- 676: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] ) <span class="ruby-keyword kw">do</span>
836
- 677:
837
- 678: <span class="ruby-comment cmt"># Check that mongrel exists </span>
838
- 679: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
839
- 680: <span class="ruby-keyword kw">begin</span>
840
- 681: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
841
- 682: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;mongrel&quot;</span>
842
- 683: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
843
- 684: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
844
- 685: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;webrick&quot;</span>
845
- 686: <span class="ruby-keyword kw">end</span>
846
- 687: <span class="ruby-keyword kw">end</span>
847
- 688:
848
- 689: <span class="ruby-comment cmt"># From rackup !!!</span>
849
- 690: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
850
- 691: <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>
851
- 692: <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>
852
- 693: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
853
- 694: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
854
- 695: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
855
- 696: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
856
- 697: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
857
- 698: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
858
- 699: <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>
859
- 700: <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>
860
- 701: <span class="ruby-keyword kw">else</span>
861
- 702: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
862
- 703: <span class="ruby-keyword kw">end</span>
863
- 704: <span class="ruby-keyword kw">else</span>
864
- 705: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
865
- 706: <span class="ruby-keyword kw">end</span>
866
- 707:
867
- 708: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>], <span class="ruby-value str">'w'</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;#{Process.pid}&quot;</span>) }
868
- 709: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) }
869
- 710: <span class="ruby-keyword kw">end</span>
870
- 711:
871
- 712: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
872
- 713: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
873
- 714: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
874
- 715: <span class="ruby-keyword kw">else</span>
875
- 716: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>)
876
- 717: <span class="ruby-keyword kw">end</span>
877
- 718: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>]) )
878
- 719:
879
- 720: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>]
880
- 721: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
881
- 722: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
882
- 723: <span class="ruby-identifier">exit</span>
883
- 724: <span class="ruby-keyword kw">end</span>
884
- 725:
885
- 726: <span class="ruby-comment cmt"># Start server</span>
886
- 727: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>].<span class="ruby-identifier">to_s</span>
887
- 728: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
888
- 729: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{conf[:host]}:#{conf[:port]}&quot;</span>
889
- 730: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
890
- 731: <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> }
891
- 732: }
892
- 733: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
893
- 734: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{conf[:host]}:#{conf[:port]}&quot;</span>
894
- 735: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">WEBrick</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
895
- 736: <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> }
896
- 737: }
897
- 738: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;thin&quot;</span>
898
- 739: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Thin on #{conf[:host]}:#{conf[:port]}&quot;</span>
899
- 740: <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-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
900
- 741: <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> }
901
- 742: }
902
- 743: <span class="ruby-keyword kw">end</span>
903
- 744: <span class="ruby-keyword kw">end</span>
904
- 745: <span class="ruby-keyword kw">end</span>
706
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 606</span>
707
+ 606: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
708
+ 607: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
709
+ 608:
710
+ 609: <span class="ruby-comment cmt"># Parse options</span>
711
+ 610: <span class="ruby-identifier">opts</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
712
+ 611: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;Usage: #{File.basename($0)} [options]&quot;</span>
713
+ 612: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
714
+ 613: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Specific options:&quot;</span>
715
+ 614:
716
+ 615: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-C&quot;</span>, <span class="ruby-value str">&quot;--console&quot;</span>, <span class="ruby-value str">&quot;Run in console mode with IRB (default: false)&quot;</span> ) {
717
+ 616: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:console</span>, <span class="ruby-keyword kw">true</span>
718
+ 617: }
719
+ 618: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-h&quot;</span>, <span class="ruby-value str">&quot;--host HOSTNAME&quot;</span>, <span class="ruby-node">&quot;Host for web server to bind to (default: #{Capcode::Configuration.get(:host)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
720
+ 619: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:host</span>, <span class="ruby-identifier">h</span>
721
+ 620: }
722
+ 621: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-p&quot;</span>, <span class="ruby-value str">&quot;--port NUM&quot;</span>, <span class="ruby-node">&quot;Port for web server (default: #{Capcode::Configuration.get(:port)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
723
+ 622: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:port</span>, <span class="ruby-identifier">p</span>
724
+ 623: }
725
+ 624: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-d&quot;</span>, <span class="ruby-value str">&quot;--daemonize [true|false]&quot;</span>, <span class="ruby-node">&quot;Daemonize (default: #{Capcode::Configuration.get(:daemonize)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
726
+ 625: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:daemonize</span>, <span class="ruby-identifier">d</span>
727
+ 626: }
728
+ 627: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-r&quot;</span>, <span class="ruby-value str">&quot;--root PATH&quot;</span>, <span class="ruby-node">&quot;Working directory (default: #{Capcode::Configuration.get(:root)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
729
+ 628: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:root</span>, <span class="ruby-identifier">w</span>
730
+ 629: }
731
+ 630: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">&quot;-s&quot;</span>, <span class="ruby-value str">&quot;--static PATH&quot;</span>, <span class="ruby-node">&quot;Static directory -- relative to the root directory (default: #{Capcode::Configuration.get(:static)})&quot;</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
732
+ 631: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:static</span>, <span class="ruby-identifier">r</span>
733
+ 632: }
734
+ 633:
735
+ 634: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;&quot;</span>
736
+ 635: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">&quot;Common options:&quot;</span>
737
+ 636:
738
+ 637: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-?&quot;</span>, <span class="ruby-value str">&quot;--help&quot;</span>, <span class="ruby-value str">&quot;Show this message&quot;</span>) <span class="ruby-keyword kw">do</span>
739
+ 638: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
740
+ 639: <span class="ruby-identifier">exit</span>
741
+ 640: <span class="ruby-keyword kw">end</span>
742
+ 641: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">&quot;-v&quot;</span>, <span class="ruby-value str">&quot;--version&quot;</span>, <span class="ruby-value str">&quot;Show versions&quot;</span>) <span class="ruby-keyword kw">do</span>
743
+ 642: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})&quot;</span>
744
+ 643: <span class="ruby-identifier">exit</span>
745
+ 644: <span class="ruby-keyword kw">end</span>
746
+ 645: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</span>( <span class="ruby-value str">&quot;-V&quot;</span>, <span class="ruby-value str">&quot;--verbose&quot;</span>, <span class="ruby-value str">&quot;Run in verbose mode&quot;</span> ) <span class="ruby-keyword kw">do</span>
747
+ 646: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:verbose</span>, <span class="ruby-keyword kw">true</span>
748
+ 647: <span class="ruby-keyword kw">end</span>
749
+ 648: <span class="ruby-keyword kw">end</span>
750
+ 649:
751
+ 650: <span class="ruby-keyword kw">begin</span>
752
+ 651: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
753
+ 652: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">ParseError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
754
+ 653: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! #{ex.message}&quot;</span>
755
+ 654: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** use `#{File.basename($0)} --help` for more details...&quot;</span>
756
+ 655: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
757
+ 656: <span class="ruby-keyword kw">end</span>
758
+ 657:
759
+ 658: <span class="ruby-comment cmt"># Run in the Working directory</span>
760
+ 659: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Go on root directory (#{File.expand_path(Capcode::Configuration.get(:root))})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
761
+ 660: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>) ) <span class="ruby-keyword kw">do</span>
762
+ 661:
763
+ 662: <span class="ruby-comment cmt"># Check that mongrel exists </span>
764
+ 663: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>).<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>) <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
765
+ 664: <span class="ruby-keyword kw">begin</span>
766
+ 665: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
767
+ 666: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:mongrel</span>
768
+ 667: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
769
+ 668: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
770
+ 669: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:webrick</span>
771
+ 670: <span class="ruby-keyword kw">end</span>
772
+ 671: <span class="ruby-keyword kw">end</span>
773
+ 672:
774
+ 673: <span class="ruby-comment cmt"># From rackup !!!</span>
775
+ 674: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:daemonize</span>)
776
+ 675: <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/java/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">RUBY_PLATFORM</span>).<span class="ruby-identifier">nil?</span>
777
+ 676: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value str">&quot;1.9&quot;</span>
778
+ 677: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
779
+ 678: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
780
+ 679: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
781
+ 680: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
782
+ 681: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
783
+ 682: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
784
+ 683: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
785
+ 684: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
786
+ 685: <span class="ruby-keyword kw">else</span>
787
+ 686: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
788
+ 687: <span class="ruby-keyword kw">end</span>
789
+ 688: <span class="ruby-keyword kw">else</span>
790
+ 689: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;!! daemonize option unavailable on #{RUBY_PLATFORM} platform.&quot;</span>
791
+ 690: <span class="ruby-keyword kw">end</span>
792
+ 691:
793
+ 692: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>), <span class="ruby-value str">'w'</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;#{Process.pid}&quot;</span>) }
794
+ 693: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>)) }
795
+ 694: <span class="ruby-keyword kw">end</span>
796
+ 695:
797
+ 696: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
798
+ 697: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
799
+ 698: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
800
+ 699: <span class="ruby-keyword kw">else</span>
801
+ 700: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>)
802
+ 701: <span class="ruby-keyword kw">end</span>
803
+ 702: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>)) )
804
+ 703:
805
+ 704: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:console</span>)
806
+ 705: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Run console...&quot;</span>
807
+ 706: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
808
+ 707: <span class="ruby-identifier">exit</span>
809
+ 708: <span class="ruby-keyword kw">end</span>
810
+ 709:
811
+ 710: <span class="ruby-comment cmt"># Start server</span>
812
+ 711: <span class="ruby-keyword kw">case</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>).<span class="ruby-identifier">to_s</span>
813
+ 712: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
814
+ 713: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
815
+ 714: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
816
+ 715: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
817
+ 716: }
818
+ 717: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
819
+ 718: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
820
+ 719: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">WEBrick</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
821
+ 720: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
822
+ 721: }
823
+ 722: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;thin&quot;</span>
824
+ 723: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}&quot;</span>
825
+ 724: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Thin</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:port</span>), <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:host</span>)} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
826
+ 725: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
827
+ 726: }
828
+ 727: <span class="ruby-keyword kw">end</span>
829
+ 728: <span class="ruby-keyword kw">end</span>
830
+ 729: <span class="ruby-keyword kw">end</span>
905
831
  </pre>
906
832
  </div>
907
833
  </div>
@@ -924,10 +850,10 @@ Session hash
924
850
  onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
925
851
  <div class="method-source-code" id="M000004-source">
926
852
  <pre>
927
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 346</span>
928
- 346: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
929
- 347: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
930
- 348: <span class="ruby-keyword kw">end</span>
853
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 347</span>
854
+ 347: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
855
+ 348: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
856
+ 349: <span class="ruby-keyword kw">end</span>
931
857
  </pre>
932
858
  </div>
933
859
  </div>
@@ -938,78 +864,17 @@ Session hash
938
864
 
939
865
  <div class="method-heading">
940
866
  <a href="#M000012" class="method-signature">
941
- <span class="method-name">set</span><span class="method-args">( key, value )</span>
867
+ <span class="method-name">set</span><span class="method-args">(key, value, opts = {})</span>
942
868
  </a>
943
869
  </div>
944
870
 
945
871
  <div class="method-description">
946
- <p>
947
- Set global configuration options
948
- </p>
949
- <p>
950
- Options :
951
- </p>
952
- <ul>
953
- <li><tt>:port</tt> = Listen port (default: 3000)
954
-
955
- </li>
956
- <li><tt>:host</tt> = Listen host (default: 0.0.0.0)
957
-
958
- </li>
959
- <li><tt>:server</tt> = Server type (webrick, mongrel or thin)
960
-
961
- </li>
962
- <li><tt>:log</tt> = Output logfile (default: STDOUT)
963
-
964
- </li>
965
- <li><tt>:<a href="Capcode.html#M000004">session</a></tt> = Session parameters.
966
- See Rack::Session for more informations
967
-
968
- </li>
969
- <li><tt>:pid</tt> = PID file (default: $0.pid)
970
-
971
- </li>
972
- <li><tt>:daemonize</tt> = Daemonize <a
973
- href="Capcode.html#M000010">application</a> (default: false)
974
-
975
- </li>
976
- <li><tt>:db_config</tt> = database configuration file (default: database.yml)
977
-
978
- </li>
979
- <li><tt>:static</tt> = Static directory (default: the working directory)
980
-
981
- </li>
982
- <li><tt>:root</tt> = Root directory (default: directory of the main.rb) &#8212;
983
- This is also the working directory !
984
-
985
- </li>
986
- <li><tt>:verbose</tt> = <a href="Capcode.html#M000011">run</a> in verbose mode
987
-
988
- </li>
989
- <li><tt>:auth</tt> = HTTP Basic Authentication options
990
-
991
- </li>
992
- </ul>
993
- <p>
994
- It can exist specifics options depending on a renderer, a helper, &#8230;
995
- </p>
996
- <p>
997
- Example :
998
- </p>
999
- <pre>
1000
- module Capcode
1001
- set :erb, &quot;/path/to/erb/files&quot;
1002
- ...
1003
- end
1004
- </pre>
1005
872
  <p><a class="source-toggle" href="#"
1006
873
  onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
1007
874
  <div class="method-source-code" id="M000012-source">
1008
875
  <pre>
1009
- <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 27</span>
1010
- 27: <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> )
1011
- 28: <span class="ruby-identifier">config</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
1012
- 29: <span class="ruby-keyword kw">end</span>
876
+ <span class="ruby-comment cmt"># File lib/capcode/configuration.rb, line 3</span>
877
+ 3: <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> = {}); <span class="ruby-constant">Configuration</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>); <span class="ruby-keyword kw">end</span>
1013
878
  </pre>
1014
879
  </div>
1015
880
  </div>
@@ -1044,10 +909,10 @@ Example :
1044
909
  onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
1045
910
  <div class="method-source-code" id="M000008-source">
1046
911
  <pre>
1047
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 488</span>
1048
- 488: <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>)
1049
- 489: <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>]
1050
- 490: <span class="ruby-keyword kw">end</span>
912
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 489</span>
913
+ 489: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use</span>(<span class="ruby-identifier">middleware</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
914
+ 490: <span class="ruby-identifier">middlewares</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span>]
915
+ 491: <span class="ruby-keyword kw">end</span>
1051
916
  </pre>
1052
917
  </div>
1053
918
  </div>