Capcode 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +10 -1
- data/doc/rdoc/classes/Capcode.html +410 -390
- data/doc/rdoc/classes/Capcode/Helpers.html +146 -126
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +26 -2
- data/doc/rdoc/files/lib/capcode/render/haml_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/json_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/sass_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode_rb.html +1 -1
- data/doc/rdoc/fr_file_index.html +5 -0
- data/examples/blog-ar.rb +81 -0
- data/examples/blog-ar.yml +3 -0
- data/examples/blog-sq.rb +82 -0
- data/examples/blog-sq.yml +3 -0
- data/examples/mail/mail_html.rhtml +1 -0
- data/examples/mail/mail_text.rhtml +1 -0
- data/examples/mail/ok.rhtml +1 -0
- data/examples/mail/rubyfr.png +0 -0
- data/examples/mustache/with_class.mustache +8 -0
- data/examples/mustache/without_class.mustache +1 -0
- data/examples/render-binary.rb +46 -0
- data/examples/render-email.rb +68 -0
- data/examples/render-erb.rb +2 -0
- data/examples/render-mustache.rb +30 -0
- data/examples/render-redirect.rb +19 -0
- data/lib/capcode.rb +3 -0
- data/lib/capcode/base/ar.rb +54 -0
- data/lib/capcode/base/couchdb.rb +5 -1
- data/lib/capcode/base/dm.rb +5 -1
- data/lib/capcode/base/sq.rb +58 -0
- data/lib/capcode/core_ext.rb +1 -1
- data/lib/capcode/render/binary.rb +8 -0
- data/lib/capcode/render/email.rb +73 -0
- data/lib/capcode/render/haml.rb +5 -1
- data/lib/capcode/render/json.rb +5 -1
- data/lib/capcode/render/markaby.rb +5 -1
- data/lib/capcode/render/mustache.rb +37 -0
- data/lib/capcode/render/none.rb +7 -0
- data/lib/capcode/render/redirect.rb +7 -0
- data/lib/capcode/render/sass.rb +5 -1
- data/lib/capcode/render/webdav.rb +11 -7
- data/lib/capcode/version.rb +1 -1
- metadata +30 -3
- data/examples/my_blog.db +0 -0
data/README.rdoc
CHANGED
@@ -12,8 +12,17 @@ Capcode is a web microframework
|
|
12
12
|
|
13
13
|
== FEATURES/PROBLEMS:
|
14
14
|
|
15
|
+
=== 0.8.8
|
16
|
+
* Add mustache renderer
|
17
|
+
* Add AcriveRecord support (see example blog-ar.rb)
|
18
|
+
* Add Sequel support (see example blog-sq.rb)
|
19
|
+
* Add Binary renderer (see example render-binary.rb)
|
20
|
+
* Add Mail renderer (see example render-mail.rb)
|
21
|
+
* Add Redirect renderer (see examples render-redirect.rb and render-mail.rb)
|
22
|
+
* Add "none" renderer (return a 204 status code)
|
23
|
+
|
15
24
|
=== 0.8.7
|
16
|
-
* Route's captures are now passed to all methods in a
|
25
|
+
* Route's captures are now passed to all methods in a controller
|
17
26
|
* Add :content_type option to renderers (see render-image.rb)
|
18
27
|
* Add Capcode.set for configuration. So Capcode::Herpers#erb_path=, Capcode::Herpers#sass_path= and Capcode::Herpers#haml_path= are deprecated, you must now use `set :erb, ...', `set :sass, ...' and `set :haml, ...' (see render-erb.rb and render-haml_sass.rb)
|
19
28
|
* Add Capcode.use to allow usage of Rack middlewares (see render-use.rb)
|
@@ -66,6 +66,14 @@
|
|
66
66
|
<a href="../files/lib/capcode/configuration_rb.html">
|
67
67
|
lib/capcode/configuration.rb
|
68
68
|
</a>
|
69
|
+
<br />
|
70
|
+
<a href="../files/lib/capcode/render/binary_rb.html">
|
71
|
+
lib/capcode/render/binary.rb
|
72
|
+
</a>
|
73
|
+
<br />
|
74
|
+
<a href="../files/lib/capcode/render/email_rb.html">
|
75
|
+
lib/capcode/render/email.rb
|
76
|
+
</a>
|
69
77
|
<br />
|
70
78
|
<a href="../files/lib/capcode/render/erb_rb.html">
|
71
79
|
lib/capcode/render/erb.rb
|
@@ -82,6 +90,18 @@
|
|
82
90
|
<a href="../files/lib/capcode/render/markaby_rb.html">
|
83
91
|
lib/capcode/render/markaby.rb
|
84
92
|
</a>
|
93
|
+
<br />
|
94
|
+
<a href="../files/lib/capcode/render/mustache_rb.html">
|
95
|
+
lib/capcode/render/mustache.rb
|
96
|
+
</a>
|
97
|
+
<br />
|
98
|
+
<a href="../files/lib/capcode/render/none_rb.html">
|
99
|
+
lib/capcode/render/none.rb
|
100
|
+
</a>
|
101
|
+
<br />
|
102
|
+
<a href="../files/lib/capcode/render/redirect_rb.html">
|
103
|
+
lib/capcode/render/redirect.rb
|
104
|
+
</a>
|
85
105
|
<br />
|
86
106
|
<a href="../files/lib/capcode/render/sass_rb.html">
|
87
107
|
lib/capcode/render/sass.rb
|
@@ -235,169 +255,169 @@ If the regexp in the route does not match, all arguments will be
|
|
235
255
|
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
236
256
|
<div class="method-source-code" id="M000001-source">
|
237
257
|
<pre>
|
238
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
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
|
-
368: <span class="ruby-comment cmt"># end</span>
|
306
|
-
369: <span class="ruby-comment cmt"># if f[:except]</span>
|
307
|
-
370: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
|
258
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 305</span>
|
259
|
+
305: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">routes_paths</span>
|
260
|
+
306: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
|
261
|
+
307: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
|
262
|
+
308: <span class="ruby-comment cmt"># < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent => /Songbird (\d\.\d)[\d\/]*?/</span>
|
263
|
+
309: <span class="ruby-comment cmt"># # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'}, </span>
|
264
|
+
310: <span class="ruby-comment cmt"># 2, </span>
|
265
|
+
311: <span class="ruby-comment cmt"># <Capcode::Klass>, </span>
|
266
|
+
312: <span class="ruby-comment cmt"># {:agent => /Songbird (\d\.\d)[\d\/]*?/} ]</span>
|
267
|
+
313: <span class="ruby-identifier">hash_of_routes</span> = {}
|
268
|
+
314: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
|
269
|
+
315: <span class="ruby-identifier">routes_paths</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
|
270
|
+
316: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current_route_path</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">String</span>
|
271
|
+
317: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">current_route_path</span> )
|
272
|
+
318: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
273
|
+
319: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">"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>)
|
274
|
+
320: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
|
275
|
+
321: <span class="ruby-keyword kw">else</span>
|
276
|
+
322: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
|
277
|
+
323: <span class="ruby-identifier">_pre</span> = <span class="ruby-value str">"/"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">_pre</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
278
|
+
324: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">"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>)
|
279
|
+
325: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">_pre</span>] = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]
|
280
|
+
326: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">max_captures_for_routes</span> <span class="ruby-operator"><</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">number_of_captures</span>
|
281
|
+
327: <span class="ruby-keyword kw">end</span>
|
282
|
+
328: <span class="ruby-keyword kw">else</span>
|
283
|
+
329: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-value str">"Bad route declaration !"</span>, <span class="ruby-identifier">caller</span>
|
284
|
+
330: <span class="ruby-keyword kw">end</span>
|
285
|
+
331: <span class="ruby-keyword kw">end</span>
|
286
|
+
332: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
|
287
|
+
333: }
|
288
|
+
334:
|
289
|
+
335: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
|
290
|
+
336: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
291
|
+
337: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
292
|
+
338: <span class="ruby-keyword kw">end</span>
|
293
|
+
339:
|
294
|
+
340: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
295
|
+
341: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
296
|
+
342: <span class="ruby-ivar">@env</span>
|
297
|
+
343: <span class="ruby-keyword kw">end</span>
|
298
|
+
344:
|
299
|
+
345: <span class="ruby-comment cmt"># Session hash</span>
|
300
|
+
346: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
301
|
+
347: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
302
|
+
348: <span class="ruby-keyword kw">end</span>
|
303
|
+
349:
|
304
|
+
350: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
|
305
|
+
351: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
306
|
+
352: <span class="ruby-ivar">@request</span>
|
307
|
+
353: <span class="ruby-keyword kw">end</span>
|
308
|
+
354:
|
309
|
+
355: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
|
310
|
+
356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
311
|
+
357: <span class="ruby-ivar">@response</span>
|
312
|
+
358: <span class="ruby-keyword kw">end</span>
|
313
|
+
359:
|
314
|
+
360: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>( <span class="ruby-identifier">e</span> ) <span class="ruby-comment cmt">#:nodoc:</span>
|
315
|
+
361: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
|
316
|
+
362: <span class="ruby-ivar">@response</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Response</span>.<span class="ruby-identifier">new</span>
|
317
|
+
363: <span class="ruby-ivar">@request</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@env</span>)
|
318
|
+
364:
|
319
|
+
365: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
|
320
|
+
366: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
|
321
|
+
367: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
|
322
|
+
368: <span class="ruby-comment cmt"># __run = true</span>
|
323
|
+
369: <span class="ruby-comment cmt"># if f[:only]</span>
|
324
|
+
370: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
|
308
325
|
371: <span class="ruby-comment cmt"># end</span>
|
309
|
-
372: <span class="ruby-comment cmt"># </span>
|
310
|
-
373: <span class="ruby-comment cmt">#
|
311
|
-
374: <span class="ruby-comment cmt">#
|
312
|
-
375: <span class="ruby-comment cmt">#
|
313
|
-
376:
|
314
|
-
377: <span class="ruby-comment cmt">#
|
315
|
-
378: <span class="ruby-
|
316
|
-
379:
|
317
|
-
380:
|
318
|
-
381:
|
319
|
-
382:
|
320
|
-
383:
|
321
|
-
384:
|
322
|
-
385:
|
323
|
-
386:
|
324
|
-
387:
|
325
|
-
388:
|
326
|
-
389:
|
327
|
-
390: <span class="ruby-keyword kw">
|
328
|
-
391:
|
329
|
-
392:
|
330
|
-
393:
|
331
|
-
394:
|
332
|
-
395:
|
333
|
-
396:
|
334
|
-
397:
|
335
|
-
398:
|
336
|
-
399:
|
337
|
-
400:
|
338
|
-
401:
|
339
|
-
402:
|
340
|
-
403:
|
341
|
-
404: <span class="ruby-
|
342
|
-
405:
|
343
|
-
406:
|
344
|
-
407: <span class="ruby-identifier">
|
345
|
-
408: <span class="ruby-
|
346
|
-
409:
|
347
|
-
410:
|
348
|
-
411:
|
349
|
-
412:
|
350
|
-
413:
|
351
|
-
414:
|
352
|
-
415:
|
353
|
-
416:
|
354
|
-
417:
|
355
|
-
418:
|
356
|
-
419:
|
357
|
-
420:
|
358
|
-
421:
|
359
|
-
422:
|
360
|
-
423: <span class="ruby-
|
361
|
-
424:
|
362
|
-
425: <span class="ruby-
|
363
|
-
426:
|
364
|
-
427: <span class="ruby-
|
365
|
-
428:
|
366
|
-
429:
|
367
|
-
430:
|
368
|
-
431:
|
369
|
-
432:
|
370
|
-
433:
|
371
|
-
434:
|
372
|
-
435:
|
373
|
-
436:
|
374
|
-
437:
|
375
|
-
438:
|
376
|
-
439:
|
377
|
-
440: <span class="ruby-identifier">
|
378
|
-
441: <span class="ruby-keyword kw">
|
379
|
-
442: <span class="ruby-identifier">_method</span> = <span class="ruby-
|
326
|
+
372: <span class="ruby-comment cmt"># if f[:except]</span>
|
327
|
+
373: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
|
328
|
+
374: <span class="ruby-comment cmt"># end</span>
|
329
|
+
375: <span class="ruby-comment cmt"># </span>
|
330
|
+
376: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
|
331
|
+
377: <span class="ruby-comment cmt"># puts "call #{proc} for #{__k}"</span>
|
332
|
+
378: <span class="ruby-comment cmt"># end</span>
|
333
|
+
379:
|
334
|
+
380: <span class="ruby-comment cmt"># Check authz</span>
|
335
|
+
381: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
|
336
|
+
382: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
337
|
+
383: <span class="ruby-identifier">authz_options</span> = <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>[<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>
|
338
|
+
384: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
|
339
|
+
385: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
|
340
|
+
386:
|
341
|
+
387: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span>, <span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
342
|
+
388: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">"^#{r.gsub(/\/$/, "")}([/]{1}.*)?$"</span>
|
343
|
+
389: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">regexp</span>).<span class="ruby-identifier">match</span>( <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span> )
|
344
|
+
390: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">size</span>
|
345
|
+
391: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
|
346
|
+
392: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
|
347
|
+
393: <span class="ruby-keyword kw">end</span>
|
348
|
+
394: <span class="ruby-keyword kw">end</span>
|
349
|
+
395: <span class="ruby-keyword kw">end</span>
|
350
|
+
396: <span class="ruby-keyword kw">end</span>
|
351
|
+
397: <span class="ruby-keyword kw">end</span>
|
352
|
+
398:
|
353
|
+
399: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
|
354
|
+
400: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
|
355
|
+
401: <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></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>] ) {
|
356
|
+
402: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
|
357
|
+
403: }
|
358
|
+
404: <span class="ruby-keyword kw">end</span>
|
359
|
+
405:
|
360
|
+
406: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
361
|
+
407: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
362
|
+
408: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
363
|
+
409:
|
364
|
+
410: <span class="ruby-identifier">aPath</span> = <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">""</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">"/"</span> )
|
365
|
+
411: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
366
|
+
412: <span class="ruby-identifier">xPath</span> = <span class="ruby-identifier">p</span>.<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">""</span> ).<span class="ruby-identifier">split</span>( <span class="ruby-value str">"/"</span> )
|
367
|
+
413: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">aPath</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
368
|
+
414: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
369
|
+
415: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
|
370
|
+
416: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">finalNArgs</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">finalNArgs</span> <span class="ruby-operator">></span> <span class="ruby-identifier">diffNArgs</span>
|
371
|
+
417: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
372
|
+
418: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
373
|
+
419: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
374
|
+
420: <span class="ruby-keyword kw">end</span>
|
375
|
+
421: <span class="ruby-keyword kw">end</span>
|
376
|
+
422:
|
377
|
+
423: <span class="ruby-keyword kw">end</span>
|
378
|
+
424:
|
379
|
+
425: <span class="ruby-identifier">nargs</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">1</span>]
|
380
|
+
426: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>][<span class="ruby-identifier">finalPath</span>] )
|
381
|
+
427: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>( <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>).<span class="ruby-identifier">gsub</span>( <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-node">"^#{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> ) )
|
382
|
+
428: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
383
|
+
429: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterError</span>, <span class="ruby-node">"Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'"</span>
|
384
|
+
430: <span class="ruby-keyword kw">else</span>
|
385
|
+
431: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">x</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)<span class="ruby-operator">?</span><span class="ruby-keyword kw">nil</span><span class="ruby-operator">:</span><span class="ruby-identifier">x</span> }
|
386
|
+
432: <span class="ruby-keyword kw">end</span>
|
387
|
+
433:
|
388
|
+
434: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">nargs</span>
|
389
|
+
435: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
390
|
+
436: <span class="ruby-keyword kw">end</span>
|
391
|
+
437:
|
392
|
+
438: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
393
|
+
439: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
394
|
+
440: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
395
|
+
441: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
396
|
+
442: <span class="ruby-identifier">_method</span> = <span class="ruby-identifier">params</span>.<span class="ruby-identifier">delete</span>( <span class="ruby-value str">"_method"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-value str">"post"</span> }
|
380
397
|
443: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
381
|
-
444:
|
382
|
-
445:
|
383
|
-
446:
|
384
|
-
447: <span class="ruby-
|
385
|
-
448:
|
386
|
-
449:
|
387
|
-
450:
|
388
|
-
451: <span class="ruby-
|
389
|
-
452: <span class="ruby-
|
390
|
-
453:
|
391
|
-
454: <span class="ruby-
|
392
|
-
455:
|
393
|
-
456:
|
394
|
-
457:
|
395
|
-
458:
|
396
|
-
459:
|
397
|
-
460:
|
398
|
-
461: <span class="ruby-
|
399
|
-
462:
|
400
|
-
463:
|
398
|
+
444: <span class="ruby-keyword kw">else</span>
|
399
|
+
445: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
400
|
+
446: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
401
|
+
447: <span class="ruby-keyword kw">end</span>
|
402
|
+
448: }
|
403
|
+
449: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_ary</span>)
|
404
|
+
450: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[0]</span>
|
405
|
+
451: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
|
406
|
+
452: <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
407
|
+
453: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
408
|
+
454: <span class="ruby-keyword kw">end</span>
|
409
|
+
455: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[2]</span>
|
410
|
+
456: <span class="ruby-keyword kw">else</span>
|
411
|
+
457: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
412
|
+
458: <span class="ruby-keyword kw">end</span>
|
413
|
+
459:
|
414
|
+
460: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
415
|
+
461: <span class="ruby-keyword kw">end</span>
|
416
|
+
462:
|
417
|
+
463: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
418
|
+
464: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
|
419
|
+
465: }
|
420
|
+
466: <span class="ruby-keyword kw">end</span>
|
401
421
|
</pre>
|
402
422
|
</div>
|
403
423
|
</div>
|
@@ -427,71 +447,71 @@ href="Capcode.html#M000012">set</a> globally
|
|
427
447
|
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
428
448
|
<div class="method-source-code" id="M000010-source">
|
429
449
|
<pre>
|
430
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
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
|
-
|
450
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 552</span>
|
451
|
+
552: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
|
452
|
+
553: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
|
453
|
+
554:
|
454
|
+
555: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
|
455
|
+
556: <span class="ruby-keyword kw">begin</span>
|
456
|
+
557: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">"Capcode::#{k}.public_methods(true).include?( '__urls__' )"</span>
|
457
|
+
558: <span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">"Capcode::#{k}.__urls__"</span>
|
458
|
+
559: <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
|
459
|
+
560: <span class="ruby-comment cmt">#raise Capcode::RouteError, "Route `#{current_route_path}' already define !", caller if @@__ROUTES.keys.include?(current_route_path)</span>
|
460
|
+
561: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteError</span>, <span class="ruby-node">"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>)
|
461
|
+
562: <span class="ruby-comment cmt">#@@__ROUTES[current_route_path] = klass.new</span>
|
462
|
+
563: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>
|
463
|
+
564: <span class="ruby-keyword kw">end</span>
|
464
|
+
565: <span class="ruby-keyword kw">end</span>
|
465
|
+
566: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
466
|
+
567: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
467
|
+
568: <span class="ruby-keyword kw">end</span>
|
468
|
+
569: <span class="ruby-keyword kw">end</span>
|
469
|
+
570:
|
470
|
+
571: <span class="ruby-comment cmt"># Set Static directory</span>
|
471
|
+
572: <span class="ruby-comment cmt">#@@__STATIC_DIR = (conf[:static][0].chr == "/")?conf[:static]:"/"+conf[:static] unless conf[:static].nil?</span>
|
472
|
+
573: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span> = (<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">chr</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"/"</span>)<span class="ruby-operator">?</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>]<span class="ruby-operator">:</span><span class="ruby-value str">"/"</span><span class="ruby-operator">+</span><span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
|
473
|
+
574:
|
474
|
+
575: <span class="ruby-comment cmt"># Initialize Rack App</span>
|
475
|
+
576: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"** Map routes."</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
476
|
+
577: <span class="ruby-comment cmt">#app = Rack::URLMap.new(@@__ROUTES)</span>
|
477
|
+
578: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>)
|
478
|
+
579: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Initialize static directory (#{conf[:static]})"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
479
|
+
580: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Static</span>.<span class="ruby-identifier">new</span>(
|
480
|
+
581: <span class="ruby-identifier">app</span>,
|
481
|
+
582: <span class="ruby-comment cmt">#:urls => [@@__STATIC_DIR], </span>
|
482
|
+
583: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">></span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
|
483
|
+
584: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">></span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>])
|
484
|
+
585: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>].<span class="ruby-identifier">nil?</span>
|
485
|
+
586: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"** Initialize session"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
486
|
+
587: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:session</span>] )
|
487
|
+
588: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
488
|
+
589: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
489
|
+
590: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
490
|
+
591: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ShowExceptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
491
|
+
592: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
492
|
+
593: <span class="ruby-comment cmt"># app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )</span>
|
493
|
+
594:
|
494
|
+
595: <span class="ruby-identifier">middlewares</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mw</span><span class="ruby-operator">|</span>
|
495
|
+
596: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
|
496
|
+
597: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Load middleware #{middleware}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
497
|
+
598: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
|
498
|
+
599: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> )
|
499
|
+
600: <span class="ruby-keyword kw">else</span>
|
500
|
+
601: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
501
|
+
602: <span class="ruby-keyword kw">end</span>
|
502
|
+
603: <span class="ruby-keyword kw">end</span>
|
503
|
+
604:
|
504
|
+
605: <span class="ruby-comment cmt"># Start database</span>
|
505
|
+
606: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">"db_connect"</span>
|
506
|
+
607: <span class="ruby-identifier">db_connect</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:db_config</span>], <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>] )
|
507
|
+
608: <span class="ruby-keyword kw">end</span>
|
508
|
+
609:
|
509
|
+
610: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
510
|
+
611: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
|
511
|
+
612: <span class="ruby-keyword kw">end</span>
|
512
|
+
613:
|
513
|
+
614: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
|
514
|
+
615: <span class="ruby-keyword kw">end</span>
|
495
515
|
</pre>
|
496
516
|
</div>
|
497
517
|
</div>
|
@@ -537,10 +557,10 @@ Hash containing all the environment variables
|
|
537
557
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
538
558
|
<div class="method-source-code" id="M000003-source">
|
539
559
|
<pre>
|
540
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
541
|
-
|
542
|
-
|
543
|
-
|
560
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 341</span>
|
561
|
+
341: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
562
|
+
342: <span class="ruby-ivar">@env</span>
|
563
|
+
343: <span class="ruby-keyword kw">end</span>
|
544
564
|
</pre>
|
545
565
|
</div>
|
546
566
|
</div>
|
@@ -595,27 +615,27 @@ The block must return a Hash of username => password like that :
|
|
595
615
|
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
596
616
|
<div class="method-source-code" id="M000009-source">
|
597
617
|
<pre>
|
598
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
618
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 509</span>
|
619
|
+
509: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">http_authentication</span>( <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span> )
|
620
|
+
510: <span class="ruby-identifier">options</span> = {
|
621
|
+
511: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:basic</span>,
|
622
|
+
512: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"Capcode.app"</span>,
|
623
|
+
513: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"opaque"</span>,
|
624
|
+
514: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"/"</span>
|
625
|
+
515: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
|
626
|
+
516:
|
627
|
+
517: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
|
628
|
+
518:
|
629
|
+
519: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
|
630
|
+
520:
|
631
|
+
521: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Array</span>
|
632
|
+
522: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
633
|
+
523: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
|
634
|
+
524: <span class="ruby-keyword kw">end</span>
|
635
|
+
525: <span class="ruby-keyword kw">else</span>
|
636
|
+
526: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
|
637
|
+
527: <span class="ruby-keyword kw">end</span>
|
638
|
+
528: <span class="ruby-keyword kw">end</span>
|
619
639
|
</pre>
|
620
640
|
</div>
|
621
641
|
</div>
|
@@ -644,11 +664,11 @@ Rack or What you want Helper
|
|
644
664
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
645
665
|
<div class="method-source-code" id="M000007-source">
|
646
666
|
<pre>
|
647
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
667
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 473</span>
|
668
|
+
473: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">route</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span> )
|
669
|
+
474: <span class="ruby-comment cmt">#@@__ROUTES[route] = yield</span>
|
670
|
+
475: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">route</span>] = <span class="ruby-keyword kw">yield</span>
|
671
|
+
476: <span class="ruby-keyword kw">end</span>
|
652
672
|
</pre>
|
653
673
|
</div>
|
654
674
|
</div>
|
@@ -672,10 +692,10 @@ parameters (GET or POST)
|
|
672
692
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
673
693
|
<div class="method-source-code" id="M000002-source">
|
674
694
|
<pre>
|
675
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
676
|
-
|
677
|
-
|
678
|
-
|
695
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 336</span>
|
696
|
+
336: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
697
|
+
337: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
698
|
+
338: <span class="ruby-keyword kw">end</span>
|
679
699
|
</pre>
|
680
700
|
</div>
|
681
701
|
</div>
|
@@ -698,10 +718,10 @@ Return the Rack::Request object
|
|
698
718
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
699
719
|
<div class="method-source-code" id="M000005-source">
|
700
720
|
<pre>
|
701
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
702
|
-
|
703
|
-
|
704
|
-
|
721
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 351</span>
|
722
|
+
351: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
723
|
+
352: <span class="ruby-ivar">@request</span>
|
724
|
+
353: <span class="ruby-keyword kw">end</span>
|
705
725
|
</pre>
|
706
726
|
</div>
|
707
727
|
</div>
|
@@ -724,10 +744,10 @@ Return the Rack::Response object
|
|
724
744
|
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
725
745
|
<div class="method-source-code" id="M000006-source">
|
726
746
|
<pre>
|
727
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
728
|
-
|
729
|
-
|
730
|
-
|
747
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 356</span>
|
748
|
+
356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
749
|
+
357: <span class="ruby-ivar">@response</span>
|
750
|
+
358: <span class="ruby-keyword kw">end</span>
|
731
751
|
</pre>
|
732
752
|
</div>
|
733
753
|
</div>
|
@@ -757,126 +777,126 @@ href="Capcode.html#M000012">set</a> globally
|
|
757
777
|
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
758
778
|
<div class="method-source-code" id="M000011-source">
|
759
779
|
<pre>
|
760
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
630: }
|
773
|
-
631: <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: #{conf[:host]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
774
|
-
632: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
|
780
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 622</span>
|
781
|
+
622: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
782
|
+
623: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
|
783
|
+
624:
|
784
|
+
625: <span class="ruby-comment cmt"># Parse options</span>
|
785
|
+
626: <span class="ruby-identifier">opts</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
|
786
|
+
627: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"Usage: #{File.basename($0)} [options]"</span>
|
787
|
+
628: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
788
|
+
629: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Specific options:"</span>
|
789
|
+
630:
|
790
|
+
631: <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> ) {
|
791
|
+
632: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>] = <span class="ruby-keyword kw">true</span>
|
775
792
|
633: }
|
776
|
-
634: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-
|
777
|
-
635: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:
|
793
|
+
634: <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: #{conf[:host]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
794
|
+
635: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
|
778
795
|
636: }
|
779
|
-
637: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-
|
780
|
-
638: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:
|
796
|
+
637: <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: #{conf[:port]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
797
|
+
638: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">p</span>
|
781
798
|
639: }
|
782
|
-
640: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-
|
783
|
-
641: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:
|
799
|
+
640: <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: #{conf[:daemonize]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
|
800
|
+
641: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span>
|
784
801
|
642: }
|
785
|
-
643: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-
|
786
|
-
644: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:
|
802
|
+
643: <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: #{conf[:root]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
|
803
|
+
644: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] = <span class="ruby-identifier">w</span>
|
787
804
|
645: }
|
788
|
-
646:
|
789
|
-
647:
|
790
|
-
648:
|
805
|
+
646: <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: #{conf[:static]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
806
|
+
647: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:static</span>] = <span class="ruby-identifier">r</span>
|
807
|
+
648: }
|
791
808
|
649:
|
792
|
-
650: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">
|
793
|
-
651:
|
794
|
-
652:
|
795
|
-
653: <span class="ruby-keyword kw">
|
796
|
-
654:
|
797
|
-
655: <span class="ruby-identifier">
|
798
|
-
656:
|
799
|
-
657: <span class="ruby-keyword kw">
|
800
|
-
658:
|
801
|
-
659: <span class="ruby-identifier">
|
802
|
-
660: <span class="ruby-keyword kw">end</span>
|
803
|
-
661:
|
804
|
-
662:
|
805
|
-
663:
|
806
|
-
664:
|
807
|
-
665:
|
808
|
-
666:
|
809
|
-
667: <span class="ruby-identifier">
|
810
|
-
668:
|
811
|
-
669:
|
812
|
-
670:
|
813
|
-
671:
|
814
|
-
672: <span class="ruby-
|
815
|
-
673:
|
816
|
-
674:
|
817
|
-
675:
|
818
|
-
676:
|
819
|
-
677:
|
820
|
-
678:
|
821
|
-
679:
|
822
|
-
680: <span class="ruby-keyword kw">
|
823
|
-
681: <span class="ruby-identifier">
|
824
|
-
682: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"
|
825
|
-
683: <span class="ruby-keyword kw">
|
826
|
-
684:
|
827
|
-
685:
|
828
|
-
686:
|
829
|
-
687: <span class="ruby-keyword kw">
|
830
|
-
688:
|
831
|
-
689:
|
832
|
-
690:
|
833
|
-
691:
|
834
|
-
692:
|
835
|
-
693: <span class="ruby-
|
836
|
-
694: <span class="ruby-constant">
|
837
|
-
695: <span class="ruby-
|
838
|
-
696: <span class="ruby-
|
839
|
-
697: <span class="ruby-constant">
|
840
|
-
698:
|
841
|
-
699: <span class="ruby-constant">
|
842
|
-
700:
|
843
|
-
701:
|
844
|
-
702:
|
845
|
-
703:
|
846
|
-
704:
|
847
|
-
705:
|
848
|
-
706: <span class="ruby-
|
849
|
-
707:
|
850
|
-
708:
|
851
|
-
709:
|
852
|
-
710: <span class="ruby-keyword kw">
|
853
|
-
711:
|
854
|
-
712: <span class="ruby-keyword kw">
|
855
|
-
713:
|
856
|
-
714:
|
857
|
-
715: <span class="ruby-
|
858
|
-
716:
|
859
|
-
717: <span class="ruby-keyword kw">
|
860
|
-
718:
|
861
|
-
719:
|
862
|
-
720:
|
863
|
-
721:
|
864
|
-
722:
|
865
|
-
723:
|
866
|
-
724: <span class="ruby-keyword kw">
|
867
|
-
725:
|
868
|
-
726:
|
869
|
-
727:
|
870
|
-
728:
|
871
|
-
729: }
|
872
|
-
730:
|
873
|
-
731:
|
874
|
-
732:
|
875
|
-
733:
|
876
|
-
734: }
|
877
|
-
735:
|
878
|
-
736:
|
879
|
-
737:
|
809
|
+
650: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
810
|
+
651: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span>
|
811
|
+
652:
|
812
|
+
653: <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>
|
813
|
+
654: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
|
814
|
+
655: <span class="ruby-identifier">exit</span>
|
815
|
+
656: <span class="ruby-keyword kw">end</span>
|
816
|
+
657: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">"-v"</span>, <span class="ruby-value str">"--version"</span>, <span class="ruby-value str">"Show versions"</span>) <span class="ruby-keyword kw">do</span>
|
817
|
+
658: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})"</span>
|
818
|
+
659: <span class="ruby-identifier">exit</span>
|
819
|
+
660: <span class="ruby-keyword kw">end</span>
|
820
|
+
661: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</span>( <span class="ruby-value str">"-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>
|
821
|
+
662: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>] = <span class="ruby-keyword kw">true</span>
|
822
|
+
663: <span class="ruby-keyword kw">end</span>
|
823
|
+
664: <span class="ruby-keyword kw">end</span>
|
824
|
+
665:
|
825
|
+
666: <span class="ruby-keyword kw">begin</span>
|
826
|
+
667: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
827
|
+
668: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">ParseError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">ex</span>
|
828
|
+
669: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
829
|
+
670: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
830
|
+
671: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
831
|
+
672: <span class="ruby-keyword kw">end</span>
|
832
|
+
673:
|
833
|
+
674: <span class="ruby-comment cmt"># Run in the Working directory</span>
|
834
|
+
675: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Go on root directory (#{File.expand_path(conf[:root])})"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:verbose</span>]
|
835
|
+
676: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] ) <span class="ruby-keyword kw">do</span>
|
836
|
+
677:
|
837
|
+
678: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
838
|
+
679: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"mongrel"</span>
|
839
|
+
680: <span class="ruby-keyword kw">begin</span>
|
840
|
+
681: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
841
|
+
682: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"mongrel"</span>
|
842
|
+
683: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
843
|
+
684: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
844
|
+
685: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"webrick"</span>
|
845
|
+
686: <span class="ruby-keyword kw">end</span>
|
846
|
+
687: <span class="ruby-keyword kw">end</span>
|
847
|
+
688:
|
848
|
+
689: <span class="ruby-comment cmt"># From rackup !!!</span>
|
849
|
+
690: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
|
850
|
+
691: <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/java/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">RUBY_PLATFORM</span>).<span class="ruby-identifier">nil?</span>
|
851
|
+
692: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator"><</span> <span class="ruby-value str">"1.9"</span>
|
852
|
+
693: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
853
|
+
694: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
854
|
+
695: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
855
|
+
696: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
856
|
+
697: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
857
|
+
698: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
858
|
+
699: <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>
|
859
|
+
700: <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>
|
860
|
+
701: <span class="ruby-keyword kw">else</span>
|
861
|
+
702: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
862
|
+
703: <span class="ruby-keyword kw">end</span>
|
863
|
+
704: <span class="ruby-keyword kw">else</span>
|
864
|
+
705: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! daemonize option unavailable on #{RUBY_PLATFORM} platform."</span>
|
865
|
+
706: <span class="ruby-keyword kw">end</span>
|
866
|
+
707:
|
867
|
+
708: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>], <span class="ruby-value str">'w'</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">"#{Process.pid}"</span>) }
|
868
|
+
709: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:pid</span>]) }
|
869
|
+
710: <span class="ruby-keyword kw">end</span>
|
870
|
+
711:
|
871
|
+
712: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
|
872
|
+
713: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
873
|
+
714: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
|
874
|
+
715: <span class="ruby-keyword kw">else</span>
|
875
|
+
716: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-identifier">conf</span>)
|
876
|
+
717: <span class="ruby-keyword kw">end</span>
|
877
|
+
718: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:log</span>]) )
|
878
|
+
719:
|
879
|
+
720: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>]
|
880
|
+
721: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"Run console..."</span>
|
881
|
+
722: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
|
882
|
+
723: <span class="ruby-identifier">exit</span>
|
883
|
+
724: <span class="ruby-keyword kw">end</span>
|
884
|
+
725:
|
885
|
+
726: <span class="ruby-comment cmt"># Start server</span>
|
886
|
+
727: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
887
|
+
728: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
888
|
+
729: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
889
|
+
730: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
|
890
|
+
731: <span class="ruby-identifier">trap</span> <span class="ruby-value str">"SIGINT"</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
|
891
|
+
732: }
|
892
|
+
733: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
893
|
+
734: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
894
|
+
735: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">WEBrick</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>]} ) { <span class="ruby-operator">|</span><span class="ruby-identifier">server</span><span class="ruby-operator">|</span>
|
895
|
+
736: <span class="ruby-identifier">trap</span> <span class="ruby-value str">"SIGINT"</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
|
896
|
+
737: }
|
897
|
+
738: <span class="ruby-keyword kw">end</span>
|
898
|
+
739: <span class="ruby-keyword kw">end</span>
|
899
|
+
740: <span class="ruby-keyword kw">end</span>
|
880
900
|
</pre>
|
881
901
|
</div>
|
882
902
|
</div>
|
@@ -899,10 +919,10 @@ Session hash
|
|
899
919
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
900
920
|
<div class="method-source-code" id="M000004-source">
|
901
921
|
<pre>
|
902
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
903
|
-
|
904
|
-
|
905
|
-
|
922
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 346</span>
|
923
|
+
346: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
924
|
+
347: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
925
|
+
348: <span class="ruby-keyword kw">end</span>
|
906
926
|
</pre>
|
907
927
|
</div>
|
908
928
|
</div>
|
@@ -1019,10 +1039,10 @@ Example :
|
|
1019
1039
|
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
1020
1040
|
<div class="method-source-code" id="M000008-source">
|
1021
1041
|
<pre>
|
1022
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1042
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 488</span>
|
1043
|
+
488: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use</span>(<span class="ruby-identifier">middleware</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
1044
|
+
489: <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>]
|
1045
|
+
490: <span class="ruby-keyword kw">end</span>
|
1026
1046
|
</pre>
|
1027
1047
|
</div>
|
1028
1048
|
</div>
|