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