Capcode 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -0
- data/doc/rdoc/classes/Capcode.html +408 -408
- data/doc/rdoc/classes/Capcode/Helpers.html +41 -43
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +7 -1
- data/doc/rdoc/files/lib/capcode_rb.html +1 -1
- data/examples/route.rb +15 -1
- data/lib/capcode.rb +5 -7
- data/lib/capcode/version.rb +1 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -220,166 +220,166 @@ If the regexp in the route does not match, all arguments will be
|
|
220
220
|
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
221
221
|
<div class="method-source-code" id="M000001-source">
|
222
222
|
<pre>
|
223
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
224
|
-
|
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
|
-
|
223
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 361</span>
|
224
|
+
361: <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>
|
225
|
+
362: <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>
|
226
|
+
363: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
|
227
|
+
364: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
|
228
|
+
365: <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>
|
229
|
+
366: <span class="ruby-comment cmt"># < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent => /Songbird (\d\.\d)[\d\/]*?/</span>
|
230
|
+
367: <span class="ruby-comment cmt"># # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'}, </span>
|
231
|
+
368: <span class="ruby-comment cmt"># 2, </span>
|
232
|
+
369: <span class="ruby-comment cmt"># <Capcode::Klass>, </span>
|
233
|
+
370: <span class="ruby-comment cmt"># {:agent => /Songbird (\d\.\d)[\d\/]*?/} ]</span>
|
234
|
+
371: <span class="ruby-identifier">hash_of_routes</span> = {}
|
235
|
+
372: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
|
236
|
+
373: <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>
|
237
|
+
374: <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>
|
238
|
+
375: <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> )
|
239
|
+
376: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
240
|
+
377: <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>)
|
241
|
+
378: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
|
242
|
+
379: <span class="ruby-keyword kw">else</span>
|
243
|
+
380: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
|
244
|
+
381: <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>
|
245
|
+
382: <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>)
|
246
|
+
383: <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>]
|
247
|
+
384: <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"><</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>
|
248
|
+
385: <span class="ruby-keyword kw">end</span>
|
249
|
+
386: <span class="ruby-keyword kw">else</span>
|
250
|
+
387: <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>
|
251
|
+
388: <span class="ruby-keyword kw">end</span>
|
252
|
+
389: <span class="ruby-keyword kw">end</span>
|
253
|
+
390: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
|
254
|
+
391: }
|
255
|
+
392:
|
256
|
+
393: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
|
257
|
+
394: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
258
|
+
395: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
259
|
+
396: <span class="ruby-keyword kw">end</span>
|
260
|
+
397:
|
261
|
+
398: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
262
|
+
399: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
263
|
+
400: <span class="ruby-ivar">@env</span>
|
264
|
+
401: <span class="ruby-keyword kw">end</span>
|
265
|
+
402:
|
266
|
+
403: <span class="ruby-comment cmt"># Session hash</span>
|
267
|
+
404: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
268
|
+
405: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
269
|
+
406: <span class="ruby-keyword kw">end</span>
|
270
|
+
407:
|
271
|
+
408: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
|
272
|
+
409: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
273
|
+
410: <span class="ruby-ivar">@request</span>
|
274
|
+
411: <span class="ruby-keyword kw">end</span>
|
275
|
+
412:
|
276
|
+
413: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
|
277
|
+
414: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
278
|
+
415: <span class="ruby-ivar">@response</span>
|
279
|
+
416: <span class="ruby-keyword kw">end</span>
|
280
|
+
417:
|
281
|
+
418: <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>
|
282
|
+
419: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
|
283
|
+
420: <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>
|
284
|
+
421: <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>)
|
285
|
+
422:
|
286
|
+
423: <span class="ruby-comment cmt"># Check authz</span>
|
287
|
+
424: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
|
288
|
+
425: <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>
|
289
|
+
426: <span class="ruby-identifier">authz_options</span> = <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>[<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>
|
290
|
+
427: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
|
291
|
+
428: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
|
292
|
+
429:
|
293
|
+
430: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span>, <span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
294
|
+
431: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">"^#{r.gsub(/\/$/, "")}([/]{1}.*)?$"</span>
|
295
|
+
432: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">regexp</span>).<span class="ruby-identifier">match</span>( <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span> )
|
296
|
+
433: <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>
|
297
|
+
434: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
|
298
|
+
435: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
|
299
|
+
436: <span class="ruby-keyword kw">end</span>
|
300
|
+
437: <span class="ruby-keyword kw">end</span>
|
301
|
+
438: <span class="ruby-keyword kw">end</span>
|
302
|
+
439: <span class="ruby-keyword kw">end</span>
|
303
|
+
440: <span class="ruby-keyword kw">end</span>
|
304
|
+
441:
|
305
|
+
442: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
|
306
|
+
443: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
|
307
|
+
444: <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>] ) {
|
308
|
+
445: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
|
309
|
+
446: }
|
310
|
+
447: <span class="ruby-keyword kw">end</span>
|
311
|
+
448:
|
312
|
+
449: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
313
|
+
450: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
314
|
+
451: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
315
|
+
452:
|
316
|
+
453: <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">""</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">"/"</span> )
|
317
|
+
454: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
318
|
+
455: <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">""</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">"/"</span> )
|
319
|
+
456: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">aPath</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
320
|
+
457: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
321
|
+
458: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
|
322
|
+
459: <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">></span> <span class="ruby-identifier">diffNArgs</span>
|
323
|
+
460: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
324
|
+
461: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
325
|
+
462: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
326
|
+
463: <span class="ruby-keyword kw">end</span>
|
327
|
+
464: <span class="ruby-keyword kw">end</span>
|
328
|
+
465: <span class="ruby-keyword kw">end</span>
|
329
|
+
466:
|
330
|
+
467: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">finalNArgs</span> <span class="ruby-operator">></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>]
|
331
|
+
468: <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>]
|
332
|
+
469: <span class="ruby-keyword kw">end</span>
|
333
|
+
470:
|
334
|
+
471: <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>]
|
335
|
+
472: <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>] )
|
336
|
+
473: <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">"^#{finalPath}"</span> ), <span class="ruby-value str">""</span> ).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">""</span> ) )
|
337
|
+
474: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
338
|
+
475: <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">"Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'"</span>
|
339
|
+
476: <span class="ruby-keyword kw">else</span>
|
340
|
+
477: <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> }
|
341
|
+
478: <span class="ruby-keyword kw">end</span>
|
342
|
+
479:
|
343
|
+
480: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">nargs</span>
|
344
|
+
481: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
345
|
+
482: <span class="ruby-keyword kw">end</span>
|
346
|
+
483:
|
347
|
+
484: <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> )
|
346
348
|
485:
|
347
|
-
486: <span class="ruby-
|
348
|
-
487:
|
349
|
-
488:
|
350
|
-
489:
|
351
|
-
490: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"
|
352
|
-
491: <span class="ruby-identifier">
|
353
|
-
492:
|
354
|
-
493:
|
355
|
-
494: <span class="ruby-identifier">
|
356
|
-
495:
|
357
|
-
496:
|
358
|
-
497:
|
359
|
-
498: <span class="ruby-
|
360
|
-
499: <span class="ruby-keyword kw">
|
361
|
-
500:
|
362
|
-
501:
|
363
|
-
502:
|
364
|
-
503:
|
365
|
-
504:
|
366
|
-
505: <span class="ruby-
|
367
|
-
506:
|
368
|
-
507: <span class="ruby-
|
369
|
-
508:
|
370
|
-
509:
|
371
|
-
510: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span
|
372
|
-
511: <span class="ruby-keyword kw">
|
373
|
-
512:
|
374
|
-
513: <span class="ruby-
|
375
|
-
514:
|
376
|
-
515:
|
377
|
-
516: <span class="ruby-
|
378
|
-
517:
|
379
|
-
518:
|
380
|
-
519:
|
381
|
-
520: }
|
382
|
-
521: <span class="ruby-keyword kw">end</span>
|
349
|
+
486: <span class="ruby-keyword kw">if</span>( <span class="ruby-identifier">filter_output</span>.<span class="ruby-identifier">nil?</span> )
|
350
|
+
487: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
351
|
+
488: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
352
|
+
489: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
353
|
+
490: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
354
|
+
491: <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-value str">"post"</span> }
|
355
|
+
492: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
356
|
+
493: <span class="ruby-keyword kw">else</span>
|
357
|
+
494: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
358
|
+
495: <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> )
|
359
|
+
496: <span class="ruby-keyword kw">end</span>
|
360
|
+
497: <span class="ruby-keyword kw">else</span>
|
361
|
+
498: <span class="ruby-identifier">filter_output</span>
|
362
|
+
499: <span class="ruby-keyword kw">end</span>
|
363
|
+
500: }
|
364
|
+
501:
|
365
|
+
502: <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>)
|
366
|
+
503: <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>
|
367
|
+
504: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
|
368
|
+
505: <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>
|
369
|
+
506: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
370
|
+
507: <span class="ruby-keyword kw">end</span>
|
371
|
+
508: <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>
|
372
|
+
509: <span class="ruby-keyword kw">else</span>
|
373
|
+
510: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
374
|
+
511: <span class="ruby-keyword kw">end</span>
|
375
|
+
512:
|
376
|
+
513: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
377
|
+
514: <span class="ruby-keyword kw">end</span>
|
378
|
+
515:
|
379
|
+
516: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
380
|
+
517: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
|
381
|
+
518: }
|
382
|
+
519: <span class="ruby-keyword kw">end</span>
|
383
383
|
</pre>
|
384
384
|
</div>
|
385
385
|
</div>
|
@@ -410,84 +410,84 @@ href="Capcode.html#M000012">set</a> globally
|
|
410
410
|
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
411
411
|
<div class="method-source-code" id="M000010-source">
|
412
412
|
<pre>
|
413
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
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
|
-
|
413
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 588</span>
|
414
|
+
588: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
|
415
|
+
589: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
|
416
|
+
590: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">print_debug</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
|
417
|
+
591:
|
418
|
+
592: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">clone</span>.<span class="ruby-identifier">delete_if</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
|
419
|
+
593: <span class="ruby-keyword kw">not</span>( <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">k</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/Capcode/</span> ) <span class="ruby-keyword kw">or</span> [
|
420
|
+
594: <span class="ruby-value str">"Filter"</span>,
|
421
|
+
595: <span class="ruby-value str">"Helpers"</span>,
|
422
|
+
596: <span class="ruby-value str">"RouteError"</span>,
|
423
|
+
597: <span class="ruby-value str">"Views"</span>,
|
424
|
+
598: <span class="ruby-value str">"ParameterError"</span>,
|
425
|
+
599: <span class="ruby-value str">"HTTPError"</span>,
|
426
|
+
600: <span class="ruby-value str">"Configuration"</span>,
|
427
|
+
601: <span class="ruby-value str">"MissingLibrary"</span>,
|
428
|
+
602: <span class="ruby-value str">"Route"</span>,
|
429
|
+
603: <span class="ruby-value str">"RenderError"</span>
|
430
|
+
604: ].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>)
|
431
|
+
605: }.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
|
432
|
+
606: <span class="ruby-keyword kw">begin</span>
|
433
|
+
607: <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>
|
434
|
+
608: <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>
|
435
|
+
609: <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
|
436
|
+
610: <span class="ruby-comment cmt">#raise Capcode::RouteError, "Route `#{current_route_path}' already define !", caller if @@__ROUTES.keys.include?(current_route_path)</span>
|
437
|
+
611: <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>)
|
438
|
+
612: <span class="ruby-comment cmt"># Capcode.routes[current_route_path] = klass.new</span>
|
439
|
+
613: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>
|
440
|
+
614: <span class="ruby-keyword kw">end</span>
|
441
|
+
615: <span class="ruby-keyword kw">end</span>
|
442
|
+
616: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
443
|
+
617: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
444
|
+
618: <span class="ruby-keyword kw">end</span>
|
445
|
+
619: <span class="ruby-keyword kw">end</span>
|
446
|
+
620:
|
447
|
+
621: <span class="ruby-comment cmt"># Set Static directory</span>
|
448
|
+
622: <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>
|
449
|
+
623:
|
450
|
+
624: <span class="ruby-comment cmt"># Initialize Rack App</span>
|
451
|
+
625: <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>)
|
452
|
+
626: <span class="ruby-comment cmt"># app = Rack::URLMap.new(Capcode.routes)</span>
|
453
|
+
627: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Ext</span><span class="ruby-operator">::</span><span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>)
|
454
|
+
628: <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>)
|
455
|
+
629: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Static</span>.<span class="ruby-identifier">new</span>(
|
456
|
+
630: <span class="ruby-identifier">app</span>,
|
457
|
+
631: <span class="ruby-comment cmt">#:urls => [@@__STATIC_DIR], </span>
|
458
|
+
632: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">></span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
|
459
|
+
633: <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>))
|
460
|
+
634: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>).<span class="ruby-identifier">nil?</span>
|
461
|
+
635: <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>)
|
462
|
+
636: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:session</span>) )
|
463
|
+
637: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
464
|
+
638: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
465
|
+
639: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
466
|
+
640: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ShowExceptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
467
|
+
641: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
468
|
+
642:
|
469
|
+
643: <span class="ruby-identifier">middlewares</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mw</span><span class="ruby-operator">|</span>
|
470
|
+
644: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
|
471
|
+
645: <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>)
|
472
|
+
646: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
|
473
|
+
647: <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> )
|
474
|
+
648: <span class="ruby-keyword kw">else</span>
|
475
|
+
649: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
476
|
+
650: <span class="ruby-keyword kw">end</span>
|
477
|
+
651: <span class="ruby-keyword kw">end</span>
|
478
|
+
652:
|
479
|
+
653: <span class="ruby-comment cmt"># Start database</span>
|
480
|
+
654: <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>
|
481
|
+
655: <span class="ruby-identifier">db_connect</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:db_config</span>), <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>) )
|
482
|
+
656: <span class="ruby-keyword kw">end</span>
|
483
|
+
657:
|
484
|
+
658: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
485
|
+
659: <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>)
|
486
|
+
660: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
|
487
|
+
661: <span class="ruby-keyword kw">end</span>
|
488
|
+
662:
|
489
|
+
663: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
|
490
|
+
664: <span class="ruby-keyword kw">end</span>
|
491
491
|
</pre>
|
492
492
|
</div>
|
493
493
|
</div>
|
@@ -551,10 +551,10 @@ Hash containing all the environment variables
|
|
551
551
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
552
552
|
<div class="method-source-code" id="M000003-source">
|
553
553
|
<pre>
|
554
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
555
|
-
|
556
|
-
|
557
|
-
|
554
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 399</span>
|
555
|
+
399: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
556
|
+
400: <span class="ruby-ivar">@env</span>
|
557
|
+
401: <span class="ruby-keyword kw">end</span>
|
558
558
|
</pre>
|
559
559
|
</div>
|
560
560
|
</div>
|
@@ -609,27 +609,27 @@ The block must return a Hash of username => password like that :
|
|
609
609
|
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
610
610
|
<div class="method-source-code" id="M000009-source">
|
611
611
|
<pre>
|
612
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
612
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 562</span>
|
613
|
+
562: <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> )
|
614
|
+
563: <span class="ruby-identifier">options</span> = {
|
615
|
+
564: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:basic</span>,
|
616
|
+
565: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"Capcode.app"</span>,
|
617
|
+
566: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"opaque"</span>,
|
618
|
+
567: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"/"</span>
|
619
|
+
568: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
|
620
|
+
569:
|
621
|
+
570: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
|
620
622
|
571:
|
621
|
-
572: <span class="ruby-
|
623
|
+
572: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
|
622
624
|
573:
|
623
|
-
574: <span class="ruby-
|
624
|
-
575:
|
625
|
-
576:
|
626
|
-
577: <span class="ruby-
|
627
|
-
578:
|
628
|
-
579: <span class="ruby-
|
629
|
-
580: <span class="ruby-keyword kw">
|
630
|
-
581:
|
631
|
-
582: <span class="ruby-keyword kw">end</span>
|
632
|
-
583: <span class="ruby-keyword kw">end</span>
|
625
|
+
574: <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>
|
626
|
+
575: <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>
|
627
|
+
576: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
|
628
|
+
577: <span class="ruby-keyword kw">end</span>
|
629
|
+
578: <span class="ruby-keyword kw">else</span>
|
630
|
+
579: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
|
631
|
+
580: <span class="ruby-keyword kw">end</span>
|
632
|
+
581: <span class="ruby-keyword kw">end</span>
|
633
633
|
</pre>
|
634
634
|
</div>
|
635
635
|
</div>
|
@@ -658,10 +658,10 @@ Rack or What you want Helper
|
|
658
658
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
659
659
|
<div class="method-source-code" id="M000007-source">
|
660
660
|
<pre>
|
661
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
662
|
-
|
663
|
-
|
664
|
-
|
661
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 527</span>
|
662
|
+
527: <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> )
|
663
|
+
528: <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>
|
664
|
+
529: <span class="ruby-keyword kw">end</span>
|
665
665
|
</pre>
|
666
666
|
</div>
|
667
667
|
</div>
|
@@ -685,10 +685,10 @@ parameters (GET or POST)
|
|
685
685
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
686
686
|
<div class="method-source-code" id="M000002-source">
|
687
687
|
<pre>
|
688
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
689
|
-
|
690
|
-
|
691
|
-
|
688
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 394</span>
|
689
|
+
394: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
690
|
+
395: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
691
|
+
396: <span class="ruby-keyword kw">end</span>
|
692
692
|
</pre>
|
693
693
|
</div>
|
694
694
|
</div>
|
@@ -711,10 +711,10 @@ Return the Rack::Request object
|
|
711
711
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
712
712
|
<div class="method-source-code" id="M000005-source">
|
713
713
|
<pre>
|
714
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
715
|
-
|
716
|
-
|
717
|
-
|
714
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 409</span>
|
715
|
+
409: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
716
|
+
410: <span class="ruby-ivar">@request</span>
|
717
|
+
411: <span class="ruby-keyword kw">end</span>
|
718
718
|
</pre>
|
719
719
|
</div>
|
720
720
|
</div>
|
@@ -737,10 +737,10 @@ Return the Rack::Response object
|
|
737
737
|
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
738
738
|
<div class="method-source-code" id="M000006-source">
|
739
739
|
<pre>
|
740
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
741
|
-
|
742
|
-
|
743
|
-
|
740
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 414</span>
|
741
|
+
414: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
742
|
+
415: <span class="ruby-ivar">@response</span>
|
743
|
+
416: <span class="ruby-keyword kw">end</span>
|
744
744
|
</pre>
|
745
745
|
</div>
|
746
746
|
</div>
|
@@ -771,131 +771,131 @@ href="Capcode.html#M000012">set</a> globally
|
|
771
771
|
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
772
772
|
<div class="method-source-code" id="M000011-source">
|
773
773
|
<pre>
|
774
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
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
|
-
|
774
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 671</span>
|
775
|
+
671: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
776
|
+
672: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
|
777
|
+
673:
|
778
|
+
674: <span class="ruby-comment cmt"># Parse options</span>
|
779
|
+
675: <span class="ruby-identifier">opts</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
|
780
|
+
676: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"Usage: #{File.basename($0)} [options]"</span>
|
781
|
+
677: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
782
|
+
678: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Specific options:"</span>
|
783
|
+
679:
|
784
|
+
680: <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> ) {
|
785
|
+
681: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:console</span>, <span class="ruby-keyword kw">true</span>
|
786
|
+
682: }
|
787
|
+
683: <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>
|
788
|
+
684: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:host</span>, <span class="ruby-identifier">h</span>
|
789
|
+
685: }
|
790
|
+
686: <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>
|
791
|
+
687: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:port</span>, <span class="ruby-identifier">p</span>
|
792
|
+
688: }
|
793
|
+
689: <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>
|
794
|
+
690: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:daemonize</span>, <span class="ruby-identifier">d</span>
|
795
|
+
691: }
|
796
|
+
692: <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>
|
797
|
+
693: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:root</span>, <span class="ruby-identifier">w</span>
|
798
|
+
694: }
|
799
|
+
695: <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>
|
800
|
+
696: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:static</span>, <span class="ruby-identifier">r</span>
|
801
|
+
697: }
|
802
|
+
698:
|
803
|
+
699: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
804
|
+
700: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span>
|
805
|
+
701:
|
806
|
+
702: <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>
|
807
|
+
703: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
|
808
|
+
704: <span class="ruby-identifier">exit</span>
|
809
|
+
705: <span class="ruby-keyword kw">end</span>
|
810
|
+
706: <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>
|
811
|
+
707: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})"</span>
|
812
|
+
708: <span class="ruby-identifier">exit</span>
|
813
|
+
709: <span class="ruby-keyword kw">end</span>
|
814
|
+
710: <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>
|
815
|
+
711: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:verbose</span>, <span class="ruby-keyword kw">true</span>
|
816
|
+
712: <span class="ruby-keyword kw">end</span>
|
817
|
+
713: <span class="ruby-keyword kw">end</span>
|
818
|
+
714:
|
819
|
+
715: <span class="ruby-keyword kw">begin</span>
|
820
|
+
716: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
821
|
+
717: <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>
|
822
|
+
718: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
823
|
+
719: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
824
|
+
720: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
825
|
+
721: <span class="ruby-keyword kw">end</span>
|
826
|
+
722:
|
827
|
+
723: <span class="ruby-comment cmt"># Run in the Working directory</span>
|
828
|
+
724: <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>)
|
829
|
+
725: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>) ) <span class="ruby-keyword kw">do</span>
|
830
|
+
726:
|
831
|
+
727: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
832
|
+
728: <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>
|
833
|
+
729: <span class="ruby-keyword kw">begin</span>
|
834
|
+
730: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
835
|
+
731: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:mongrel</span>
|
836
|
+
732: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
837
|
+
733: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
838
|
+
734: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:webrick</span>
|
839
|
+
735: <span class="ruby-keyword kw">end</span>
|
840
|
+
736: <span class="ruby-keyword kw">end</span>
|
841
|
+
737:
|
842
|
+
738: <span class="ruby-comment cmt"># From rackup !!!</span>
|
843
|
+
739: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:daemonize</span>)
|
844
|
+
740: <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/java/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">RUBY_PLATFORM</span>).<span class="ruby-identifier">nil?</span>
|
845
|
+
741: <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>
|
846
|
+
742: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
847
|
+
743: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
846
848
|
744: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
847
|
-
745: <span class="ruby-
|
848
|
-
746: <span class="ruby-
|
849
|
-
747: <span class="ruby-
|
850
|
-
748: <span class="ruby-constant">
|
851
|
-
749: <span class="ruby-constant">
|
852
|
-
750:
|
853
|
-
751: <span class="ruby-constant">
|
854
|
-
752: <span class="ruby-keyword kw">
|
855
|
-
753:
|
856
|
-
754: <span class="ruby-
|
857
|
-
755: <span class="ruby-keyword kw">
|
858
|
-
756:
|
859
|
-
757: <span class="ruby-
|
860
|
-
758:
|
861
|
-
759:
|
862
|
-
760:
|
863
|
-
761: <span class="ruby-keyword kw">
|
864
|
-
762:
|
865
|
-
763:
|
866
|
-
764: <span class="ruby-keyword kw">
|
867
|
-
765: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>)
|
868
|
-
766: <span class="ruby-keyword kw">
|
869
|
-
767:
|
870
|
-
768:
|
871
|
-
769: <span class="ruby-
|
872
|
-
770:
|
873
|
-
771:
|
874
|
-
772: <span class="ruby-identifier">
|
875
|
-
773:
|
876
|
-
774:
|
877
|
-
775: <span class="ruby-
|
878
|
-
776:
|
879
|
-
777: <span class="ruby-
|
880
|
-
778:
|
881
|
-
779:
|
882
|
-
780:
|
883
|
-
781:
|
884
|
-
782:
|
885
|
-
783: }
|
886
|
-
784:
|
887
|
-
785:
|
888
|
-
786:
|
889
|
-
787:
|
890
|
-
788: }
|
891
|
-
789:
|
892
|
-
790:
|
893
|
-
791:
|
894
|
-
792:
|
895
|
-
793:
|
896
|
-
794:
|
897
|
-
795: <span class="ruby-keyword kw">end</span>
|
898
|
-
796: <span class="ruby-keyword kw">end</span>
|
849
|
+
745: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
850
|
+
746: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
851
|
+
747: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
852
|
+
748: <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>
|
853
|
+
749: <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>
|
854
|
+
750: <span class="ruby-keyword kw">else</span>
|
855
|
+
751: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
856
|
+
752: <span class="ruby-keyword kw">end</span>
|
857
|
+
753: <span class="ruby-keyword kw">else</span>
|
858
|
+
754: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! daemonize option unavailable on #{RUBY_PLATFORM} platform."</span>
|
859
|
+
755: <span class="ruby-keyword kw">end</span>
|
860
|
+
756:
|
861
|
+
757: <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>) }
|
862
|
+
758: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>)) }
|
863
|
+
759: <span class="ruby-keyword kw">end</span>
|
864
|
+
760:
|
865
|
+
761: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
|
866
|
+
762: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
867
|
+
763: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
|
868
|
+
764: <span class="ruby-keyword kw">else</span>
|
869
|
+
765: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>)
|
870
|
+
766: <span class="ruby-keyword kw">end</span>
|
871
|
+
767: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>)) )
|
872
|
+
768:
|
873
|
+
769: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:console</span>)
|
874
|
+
770: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"Run console..."</span>
|
875
|
+
771: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
|
876
|
+
772: <span class="ruby-identifier">exit</span>
|
877
|
+
773: <span class="ruby-keyword kw">end</span>
|
878
|
+
774:
|
879
|
+
775: <span class="ruby-comment cmt"># Start server</span>
|
880
|
+
776: <span class="ruby-keyword kw">case</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>).<span class="ruby-identifier">to_s</span>
|
881
|
+
777: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
882
|
+
778: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"</span>
|
883
|
+
779: <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>
|
884
|
+
780: <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> }
|
885
|
+
781: }
|
886
|
+
782: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
887
|
+
783: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"</span>
|
888
|
+
784: <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>
|
889
|
+
785: <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> }
|
890
|
+
786: }
|
891
|
+
787: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"thin"</span>
|
892
|
+
788: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"</span>
|
893
|
+
789: <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>
|
894
|
+
790: <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> }
|
895
|
+
791: }
|
896
|
+
792: <span class="ruby-keyword kw">end</span>
|
897
|
+
793: <span class="ruby-keyword kw">end</span>
|
898
|
+
794: <span class="ruby-keyword kw">end</span>
|
899
899
|
</pre>
|
900
900
|
</div>
|
901
901
|
</div>
|
@@ -918,10 +918,10 @@ Session hash
|
|
918
918
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
919
919
|
<div class="method-source-code" id="M000004-source">
|
920
920
|
<pre>
|
921
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
922
|
-
|
923
|
-
|
924
|
-
|
921
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 404</span>
|
922
|
+
404: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
923
|
+
405: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
924
|
+
406: <span class="ruby-keyword kw">end</span>
|
925
925
|
</pre>
|
926
926
|
</div>
|
927
927
|
</div>
|
@@ -977,10 +977,10 @@ Example :
|
|
977
977
|
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
978
978
|
<div class="method-source-code" id="M000008-source">
|
979
979
|
<pre>
|
980
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
981
|
-
|
982
|
-
|
983
|
-
|
980
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 541</span>
|
981
|
+
541: <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>)
|
982
|
+
542: <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>]
|
983
|
+
543: <span class="ruby-keyword kw">end</span>
|
984
984
|
</pre>
|
985
985
|
</div>
|
986
986
|
</div>
|