Capcode 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -5
- data/doc/rdoc/classes/Capcode.html +394 -394
- data/doc/rdoc/classes/Capcode/Helpers.html +88 -78
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +20 -6
- data/doc/rdoc/files/lib/capcode_rb.html +2 -2
- data/examples/render-image.rb +2 -3
- data/examples/rest.rb +0 -1
- data/examples/sample.rb +0 -4
- data/examples/soapbox/soapbox.rb +0 -1
- data/examples/upload.rb +0 -2
- data/lib/capcode.rb +21 -11
- data/lib/capcode/core_ext.rb +5 -0
- data/lib/capcode/version.rb +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -12,6 +12,10 @@ Capcode is a web microframework
|
|
12
12
|
|
13
13
|
== FEATURES/PROBLEMS:
|
14
14
|
|
15
|
+
=== 0.9.1
|
16
|
+
* You don't need to require the renderers. This will be done by Capcode at use time.
|
17
|
+
* Major bug correction for jRuby
|
18
|
+
|
15
19
|
=== 0.9.0
|
16
20
|
|
17
21
|
* <b>IMPORTANT</b>
|
@@ -224,12 +228,13 @@ See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for co
|
|
224
228
|
# file: sample.rb
|
225
229
|
require 'rubygems'
|
226
230
|
require 'capcode'
|
227
|
-
require 'capcode/render/markaby'
|
228
231
|
|
229
232
|
module Capcode
|
230
233
|
class Hello < Route '/hello'
|
231
234
|
def get
|
232
235
|
@t = Time.now
|
236
|
+
|
237
|
+
# This implies that capcode-render-markaby is installed !
|
233
238
|
render :markaby => :time
|
234
239
|
end
|
235
240
|
end
|
@@ -256,13 +261,15 @@ See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for co
|
|
256
261
|
# file: sample.rb
|
257
262
|
require 'rubygems'
|
258
263
|
require 'capcode'
|
259
|
-
require 'capcode/render/haml'
|
260
|
-
Capcode::Helpers.haml_path = "./my_haml_views"
|
261
264
|
|
262
265
|
module Capcode
|
266
|
+
set :haml, "./my_haml_views"
|
267
|
+
|
263
268
|
class Hello < Route '/hello'
|
264
269
|
def get
|
265
270
|
@t = Time.now
|
271
|
+
|
272
|
+
# This implies that capcode-render-haml is installed !
|
266
273
|
render :haml => :time
|
267
274
|
end
|
268
275
|
end
|
@@ -282,12 +289,13 @@ See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for co
|
|
282
289
|
# file: sample.rb
|
283
290
|
require 'rubygems'
|
284
291
|
require 'capcode'
|
285
|
-
require 'capcode/render/json'
|
286
292
|
|
287
293
|
module Capcode
|
288
294
|
class Hello < Route '/hello'
|
289
295
|
def get
|
290
296
|
@t = Time.now
|
297
|
+
|
298
|
+
# This implies that capcode-render-json is installed !
|
291
299
|
render :json => { :time => @t }
|
292
300
|
end
|
293
301
|
end
|
@@ -300,13 +308,13 @@ See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for co
|
|
300
308
|
# file: sample.rb
|
301
309
|
require 'rubygems'
|
302
310
|
require 'capcode'
|
303
|
-
require 'capcode/render/webdav'
|
304
311
|
|
305
312
|
module Capcode
|
306
313
|
|
307
314
|
# !!! Render file from /Users/greg/temp !!!
|
308
315
|
class WebDav < Route '/temp'
|
309
316
|
def get
|
317
|
+
# This implies that capcode-render-webdav is installed !
|
310
318
|
render :webdav => "/Users/greg/temp"
|
311
319
|
end
|
312
320
|
|
@@ -202,169 +202,169 @@ If the regexp in the route does not match, all arguments will be
|
|
202
202
|
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
203
203
|
<div class="method-source-code" id="M000001-source">
|
204
204
|
<pre>
|
205
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
339: <span class="ruby-keyword kw">end</span>
|
240
|
-
340:
|
241
|
-
341: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
242
|
-
342: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
243
|
-
343: <span class="ruby-ivar">@env</span>
|
244
|
-
344: <span class="ruby-keyword kw">end</span>
|
245
|
-
345:
|
246
|
-
346: <span class="ruby-comment cmt"># Session hash</span>
|
247
|
-
347: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
248
|
-
348: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
205
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 316</span>
|
206
|
+
316: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">routes_paths</span>
|
207
|
+
317: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
|
208
|
+
318: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>) {
|
209
|
+
319: <span class="ruby-comment cmt"># < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)', :agent => /Songbird (\d\.\d)[\d\/]*?/</span>
|
210
|
+
320: <span class="ruby-comment cmt"># # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'}, </span>
|
211
|
+
321: <span class="ruby-comment cmt"># 2, </span>
|
212
|
+
322: <span class="ruby-comment cmt"># <Capcode::Klass>, </span>
|
213
|
+
323: <span class="ruby-comment cmt"># {:agent => /Songbird (\d\.\d)[\d\/]*?/} ]</span>
|
214
|
+
324: <span class="ruby-identifier">hash_of_routes</span> = {}
|
215
|
+
325: <span class="ruby-identifier">max_captures_for_routes</span> = <span class="ruby-value">0</span>
|
216
|
+
326: <span class="ruby-identifier">routes_paths</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
|
217
|
+
327: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current_route_path</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">String</span>
|
218
|
+
328: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">current_route_path</span> )
|
219
|
+
329: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
220
|
+
330: <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>)
|
221
|
+
331: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-value str">''</span>
|
222
|
+
332: <span class="ruby-keyword kw">else</span>
|
223
|
+
333: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
|
224
|
+
334: <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>
|
225
|
+
335: <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>)
|
226
|
+
336: <span class="ruby-identifier">hash_of_routes</span>[<span class="ruby-identifier">_pre</span>] = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]
|
227
|
+
337: <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>
|
228
|
+
338: <span class="ruby-keyword kw">end</span>
|
229
|
+
339: <span class="ruby-keyword kw">else</span>
|
230
|
+
340: <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>
|
231
|
+
341: <span class="ruby-keyword kw">end</span>
|
232
|
+
342: <span class="ruby-keyword kw">end</span>
|
233
|
+
343: [<span class="ruby-identifier">hash_of_routes</span>, <span class="ruby-identifier">max_captures_for_routes</span>, <span class="ruby-keyword kw">self</span>]
|
234
|
+
344: }
|
235
|
+
345:
|
236
|
+
346: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
|
237
|
+
347: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
238
|
+
348: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
249
239
|
349: <span class="ruby-keyword kw">end</span>
|
250
240
|
350:
|
251
|
-
351: <span class="ruby-comment cmt">#
|
252
|
-
352: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
253
|
-
353: <span class="ruby-ivar">@
|
241
|
+
351: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
242
|
+
352: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
243
|
+
353: <span class="ruby-ivar">@env</span>
|
254
244
|
354: <span class="ruby-keyword kw">end</span>
|
255
245
|
355:
|
256
|
-
356: <span class="ruby-comment cmt">#
|
257
|
-
357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">
|
258
|
-
358: <span class="ruby-ivar">@
|
246
|
+
356: <span class="ruby-comment cmt"># Session hash</span>
|
247
|
+
357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
248
|
+
358: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
259
249
|
359: <span class="ruby-keyword kw">end</span>
|
260
250
|
360:
|
261
|
-
361: <span class="ruby-
|
262
|
-
362:
|
263
|
-
363: <span class="ruby-ivar">@
|
264
|
-
364:
|
265
|
-
365:
|
266
|
-
366:
|
267
|
-
367:
|
268
|
-
368: <span class="ruby-
|
269
|
-
369:
|
270
|
-
370:
|
271
|
-
371:
|
272
|
-
372: <span class="ruby-
|
273
|
-
373: <span class="ruby-
|
274
|
-
374: <span class="ruby-
|
275
|
-
375:
|
276
|
-
376: <span class="ruby-comment cmt">#
|
277
|
-
377: <span class="ruby-comment cmt">#
|
278
|
-
378: <span class="ruby-comment cmt">#
|
279
|
-
379: <span class="ruby-comment cmt">#
|
280
|
-
380:
|
281
|
-
381: <span class="ruby-comment cmt">#
|
282
|
-
382: <span class="ruby-
|
283
|
-
383: <span class="ruby-
|
284
|
-
384:
|
285
|
-
385:
|
286
|
-
386:
|
287
|
-
387:
|
288
|
-
388:
|
289
|
-
389:
|
290
|
-
390:
|
291
|
-
391:
|
292
|
-
392:
|
293
|
-
393:
|
294
|
-
394:
|
295
|
-
395:
|
296
|
-
396: <span class="ruby-keyword kw">
|
297
|
-
397:
|
298
|
-
398:
|
299
|
-
399:
|
300
|
-
400:
|
301
|
-
401:
|
302
|
-
402:
|
303
|
-
403:
|
304
|
-
404:
|
305
|
-
405:
|
306
|
-
406:
|
307
|
-
407: <span class="ruby-
|
308
|
-
408:
|
309
|
-
409:
|
310
|
-
410:
|
311
|
-
411: <span class="ruby-
|
312
|
-
412:
|
313
|
-
413:
|
314
|
-
414:
|
315
|
-
415:
|
316
|
-
416:
|
317
|
-
417:
|
318
|
-
418:
|
319
|
-
419:
|
320
|
-
420:
|
321
|
-
421:
|
322
|
-
422:
|
323
|
-
423:
|
324
|
-
424:
|
325
|
-
425:
|
326
|
-
426:
|
327
|
-
427:
|
328
|
-
428:
|
329
|
-
429:
|
330
|
-
430:
|
331
|
-
431:
|
332
|
-
432: <span class="ruby-
|
333
|
-
433:
|
334
|
-
434:
|
335
|
-
435:
|
336
|
-
436:
|
337
|
-
437: <span class="ruby-keyword kw">
|
338
|
-
438:
|
339
|
-
439: <span class="ruby-keyword kw">
|
340
|
-
440: <span class="ruby-
|
341
|
-
441:
|
342
|
-
442: <span class="ruby-
|
343
|
-
443:
|
344
|
-
444:
|
345
|
-
445:
|
346
|
-
446:
|
347
|
-
447:
|
348
|
-
448:
|
349
|
-
449:
|
350
|
-
450:
|
351
|
-
451:
|
352
|
-
452:
|
353
|
-
453:
|
354
|
-
454:
|
355
|
-
455:
|
356
|
-
456:
|
357
|
-
457:
|
358
|
-
458: <span class="ruby-
|
359
|
-
459:
|
360
|
-
460:
|
361
|
-
461:
|
362
|
-
462:
|
363
|
-
463:
|
364
|
-
464:
|
365
|
-
465:
|
366
|
-
466:
|
367
|
-
467:
|
251
|
+
361: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
|
252
|
+
362: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
253
|
+
363: <span class="ruby-ivar">@request</span>
|
254
|
+
364: <span class="ruby-keyword kw">end</span>
|
255
|
+
365:
|
256
|
+
366: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
|
257
|
+
367: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
258
|
+
368: <span class="ruby-ivar">@response</span>
|
259
|
+
369: <span class="ruby-keyword kw">end</span>
|
260
|
+
370:
|
261
|
+
371: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>( <span class="ruby-identifier">e</span> ) <span class="ruby-comment cmt">#:nodoc:</span>
|
262
|
+
372: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
|
263
|
+
373: <span class="ruby-ivar">@response</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Response</span>.<span class="ruby-identifier">new</span>
|
264
|
+
374: <span class="ruby-ivar">@request</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@env</span>)
|
265
|
+
375:
|
266
|
+
376: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
|
267
|
+
377: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
|
268
|
+
378: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
|
269
|
+
379: <span class="ruby-comment cmt"># __run = true</span>
|
270
|
+
380: <span class="ruby-comment cmt"># if f[:only]</span>
|
271
|
+
381: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
|
272
|
+
382: <span class="ruby-comment cmt"># end</span>
|
273
|
+
383: <span class="ruby-comment cmt"># if f[:except]</span>
|
274
|
+
384: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
|
275
|
+
385: <span class="ruby-comment cmt"># end</span>
|
276
|
+
386: <span class="ruby-comment cmt"># </span>
|
277
|
+
387: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
|
278
|
+
388: <span class="ruby-comment cmt"># puts "call #{proc} for #{__k}"</span>
|
279
|
+
389: <span class="ruby-comment cmt"># end</span>
|
280
|
+
390:
|
281
|
+
391: <span class="ruby-comment cmt"># Check authz</span>
|
282
|
+
392: <span class="ruby-identifier">authz_options</span> = <span class="ruby-keyword kw">nil</span>
|
283
|
+
393: <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>
|
284
|
+
394: <span class="ruby-identifier">authz_options</span> = <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>[<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>
|
285
|
+
395: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
|
286
|
+
396: <span class="ruby-identifier">route</span> = <span class="ruby-keyword kw">nil</span>
|
287
|
+
397:
|
288
|
+
398: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">__auth__</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span>, <span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
289
|
+
399: <span class="ruby-identifier">regexp</span> = <span class="ruby-node">"^#{r.gsub(/\/$/, "")}([/]{1}.*)?$"</span>
|
290
|
+
400: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">regexp</span>).<span class="ruby-identifier">match</span>( <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">path</span> )
|
291
|
+
401: <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>
|
292
|
+
402: <span class="ruby-identifier">route</span> = <span class="ruby-identifier">r</span>
|
293
|
+
403: <span class="ruby-identifier">authz_options</span> = <span class="ruby-identifier">o</span>
|
294
|
+
404: <span class="ruby-keyword kw">end</span>
|
295
|
+
405: <span class="ruby-keyword kw">end</span>
|
296
|
+
406: <span class="ruby-keyword kw">end</span>
|
297
|
+
407: <span class="ruby-keyword kw">end</span>
|
298
|
+
408: <span class="ruby-keyword kw">end</span>
|
299
|
+
409:
|
300
|
+
410: <span class="ruby-identifier">r</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:halt</span>) {
|
301
|
+
411: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">authz_options</span>.<span class="ruby-identifier">nil?</span>
|
302
|
+
412: <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>] ) {
|
303
|
+
413: <span class="ruby-identifier">authz_options</span>[<span class="ruby-identifier">:autz</span>]
|
304
|
+
414: }
|
305
|
+
415: <span class="ruby-keyword kw">end</span>
|
306
|
+
416:
|
307
|
+
417: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
308
|
+
418: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
309
|
+
419: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
310
|
+
420:
|
311
|
+
421: <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> )
|
312
|
+
422: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
313
|
+
423: <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> )
|
314
|
+
424: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">aPath</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
315
|
+
425: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
316
|
+
426: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
|
317
|
+
427: <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>
|
318
|
+
428: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
319
|
+
429: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
320
|
+
430: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
321
|
+
431: <span class="ruby-keyword kw">end</span>
|
322
|
+
432: <span class="ruby-keyword kw">end</span>
|
323
|
+
433:
|
324
|
+
434: <span class="ruby-keyword kw">end</span>
|
325
|
+
435:
|
326
|
+
436: <span class="ruby-identifier">nargs</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">1</span>]
|
327
|
+
437: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>( <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__urls__</span>[<span class="ruby-value">0</span>][<span class="ruby-identifier">finalPath</span>] )
|
328
|
+
438: <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> ) )
|
329
|
+
439: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
330
|
+
440: <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>
|
331
|
+
441: <span class="ruby-keyword kw">else</span>
|
332
|
+
442: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">x</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)<span class="ruby-operator">?</span><span class="ruby-keyword kw">nil</span><span class="ruby-operator">:</span><span class="ruby-identifier">x</span> }
|
333
|
+
443: <span class="ruby-keyword kw">end</span>
|
334
|
+
444:
|
335
|
+
445: <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>
|
336
|
+
446: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
337
|
+
447: <span class="ruby-keyword kw">end</span>
|
338
|
+
448:
|
339
|
+
449: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
340
|
+
450: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
341
|
+
451: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
342
|
+
452: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
343
|
+
453: <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> }
|
344
|
+
454: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
345
|
+
455: <span class="ruby-keyword kw">else</span>
|
346
|
+
456: <span class="ruby-identifier">_method</span> = <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
347
|
+
457: <span class="ruby-identifier">send</span>( <span class="ruby-identifier">_method</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
348
|
+
458: <span class="ruby-keyword kw">end</span>
|
349
|
+
459: }
|
350
|
+
460: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_ary</span>)
|
351
|
+
461: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[0]</span>
|
352
|
+
462: <span class="ruby-comment cmt">#r[1].each do |k,v|</span>
|
353
|
+
463: <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
354
|
+
464: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
355
|
+
465: <span class="ruby-keyword kw">end</span>
|
356
|
+
466: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>.<span class="ruby-identifier">shift</span> <span class="ruby-comment cmt">#r[2]</span>
|
357
|
+
467: <span class="ruby-keyword kw">else</span>
|
358
|
+
468: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
359
|
+
469: <span class="ruby-keyword kw">end</span>
|
360
|
+
470:
|
361
|
+
471: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
362
|
+
472: <span class="ruby-keyword kw">end</span>
|
363
|
+
473:
|
364
|
+
474: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
365
|
+
475: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
|
366
|
+
476: }
|
367
|
+
477: <span class="ruby-keyword kw">end</span>
|
368
368
|
</pre>
|
369
369
|
</div>
|
370
370
|
</div>
|
@@ -395,71 +395,71 @@ href="Capcode.html#M000012">set</a> globally
|
|
395
395
|
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
396
396
|
<div class="method-source-code" id="M000010-source">
|
397
397
|
<pre>
|
398
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
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
|
-
578:
|
442
|
-
579: <span class="ruby-identifier">middlewares</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mw</span><span class="ruby-operator">|</span>
|
443
|
-
580: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
|
444
|
-
581: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** 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>)
|
445
|
-
582: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
|
446
|
-
583: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> )
|
447
|
-
584: <span class="ruby-keyword kw">else</span>
|
448
|
-
585: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
449
|
-
586: <span class="ruby-keyword kw">end</span>
|
450
|
-
587: <span class="ruby-keyword kw">end</span>
|
398
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 546</span>
|
399
|
+
546: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">application</span>( <span class="ruby-identifier">args</span> = {} )
|
400
|
+
547: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
|
401
|
+
548:
|
402
|
+
549: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
|
403
|
+
550: <span class="ruby-keyword kw">begin</span>
|
404
|
+
551: <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>
|
405
|
+
552: <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>
|
406
|
+
553: <span class="ruby-identifier">hash_of_routes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">current_route_path</span><span class="ruby-operator">|</span>
|
407
|
+
554: <span class="ruby-comment cmt">#raise Capcode::RouteError, "Route `#{current_route_path}' already define !", caller if @@__ROUTES.keys.include?(current_route_path)</span>
|
408
|
+
555: <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>)
|
409
|
+
556: <span class="ruby-comment cmt">#@@__ROUTES[current_route_path] = klass.new</span>
|
410
|
+
557: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">current_route_path</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>
|
411
|
+
558: <span class="ruby-keyword kw">end</span>
|
412
|
+
559: <span class="ruby-keyword kw">end</span>
|
413
|
+
560: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
414
|
+
561: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
415
|
+
562: <span class="ruby-keyword kw">end</span>
|
416
|
+
563: <span class="ruby-keyword kw">end</span>
|
417
|
+
564:
|
418
|
+
565: <span class="ruby-comment cmt"># Set Static directory</span>
|
419
|
+
566: <span class="ruby-comment cmt">#@@__STATIC_DIR = (conf[:static][0].chr == "/")?conf[:static]:"/"+conf[:static] unless conf[:static].nil?</span>
|
420
|
+
567: <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>
|
421
|
+
568:
|
422
|
+
569: <span class="ruby-comment cmt"># Initialize Rack App</span>
|
423
|
+
570: <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>)
|
424
|
+
571: <span class="ruby-comment cmt">#app = Rack::URLMap.new(@@__ROUTES)</span>
|
425
|
+
572: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">URLMap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>)
|
426
|
+
573: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Initialize static directory (#{Capcode::Configuration.get(:static)})"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:verbose</span>)
|
427
|
+
574: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Static</span>.<span class="ruby-identifier">new</span>(
|
428
|
+
575: <span class="ruby-identifier">app</span>,
|
429
|
+
576: <span class="ruby-comment cmt">#:urls => [@@__STATIC_DIR], </span>
|
430
|
+
577: <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">></span> [<span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>],
|
431
|
+
578: <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>))
|
432
|
+
579: ) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:static</span>).<span class="ruby-identifier">nil?</span>
|
433
|
+
580: <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>)
|
434
|
+
581: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:session</span>) )
|
435
|
+
582: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
436
|
+
583: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
437
|
+
584: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
438
|
+
585: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ShowExceptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>)
|
439
|
+
586: <span class="ruby-comment cmt">#app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
440
|
+
587: <span class="ruby-comment cmt"># app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )</span>
|
451
441
|
588:
|
452
|
-
589: <span class="ruby-
|
453
|
-
590:
|
454
|
-
591: <span class="ruby-identifier">
|
455
|
-
592:
|
456
|
-
593:
|
457
|
-
594:
|
458
|
-
595:
|
459
|
-
596:
|
460
|
-
597:
|
461
|
-
598:
|
462
|
-
599:
|
442
|
+
589: <span class="ruby-identifier">middlewares</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mw</span><span class="ruby-operator">|</span>
|
443
|
+
590: <span class="ruby-identifier">middleware</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">block</span> = <span class="ruby-identifier">mw</span>
|
444
|
+
591: <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>)
|
445
|
+
592: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
|
446
|
+
593: <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> )
|
447
|
+
594: <span class="ruby-keyword kw">else</span>
|
448
|
+
595: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
449
|
+
596: <span class="ruby-keyword kw">end</span>
|
450
|
+
597: <span class="ruby-keyword kw">end</span>
|
451
|
+
598:
|
452
|
+
599: <span class="ruby-comment cmt"># Start database</span>
|
453
|
+
600: <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>
|
454
|
+
601: <span class="ruby-identifier">db_connect</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:db_config</span>), <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>) )
|
455
|
+
602: <span class="ruby-keyword kw">end</span>
|
456
|
+
603:
|
457
|
+
604: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
458
|
+
605: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
|
459
|
+
606: <span class="ruby-keyword kw">end</span>
|
460
|
+
607:
|
461
|
+
608: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">app</span>
|
462
|
+
609: <span class="ruby-keyword kw">end</span>
|
463
463
|
</pre>
|
464
464
|
</div>
|
465
465
|
</div>
|
@@ -482,10 +482,10 @@ Hash containing all the environment variables
|
|
482
482
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
483
483
|
<div class="method-source-code" id="M000003-source">
|
484
484
|
<pre>
|
485
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
486
|
-
|
487
|
-
|
488
|
-
|
485
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 352</span>
|
486
|
+
352: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
487
|
+
353: <span class="ruby-ivar">@env</span>
|
488
|
+
354: <span class="ruby-keyword kw">end</span>
|
489
489
|
</pre>
|
490
490
|
</div>
|
491
491
|
</div>
|
@@ -540,27 +540,27 @@ The block must return a Hash of username => password like that :
|
|
540
540
|
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
541
541
|
<div class="method-source-code" id="M000009-source">
|
542
542
|
<pre>
|
543
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
543
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 520</span>
|
544
|
+
520: <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> )
|
545
|
+
521: <span class="ruby-identifier">options</span> = {
|
546
|
+
522: <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:basic</span>,
|
547
|
+
523: <span class="ruby-identifier">:realm</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"Capcode.app"</span>,
|
548
|
+
524: <span class="ruby-identifier">:opaque</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"opaque"</span>,
|
549
|
+
525: <span class="ruby-identifier">:routes</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"/"</span>
|
550
|
+
526: }.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">opts</span> )
|
551
|
+
527:
|
552
|
+
528: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:autz</span>] = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>()
|
553
|
+
529:
|
554
|
+
530: <span class="ruby-ivar">@__auth__</span> <span class="ruby-operator">||=</span> {}
|
555
|
+
531:
|
556
|
+
532: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Array</span>
|
557
|
+
533: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
|
558
|
+
534: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-identifier">options</span>
|
559
|
+
535: <span class="ruby-keyword kw">end</span>
|
560
|
+
536: <span class="ruby-keyword kw">else</span>
|
561
|
+
537: <span class="ruby-ivar">@__auth__</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:routes</span>]] = <span class="ruby-identifier">options</span>
|
562
|
+
538: <span class="ruby-keyword kw">end</span>
|
563
|
+
539: <span class="ruby-keyword kw">end</span>
|
564
564
|
</pre>
|
565
565
|
</div>
|
566
566
|
</div>
|
@@ -589,11 +589,11 @@ Rack or What you want Helper
|
|
589
589
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
590
590
|
<div class="method-source-code" id="M000007-source">
|
591
591
|
<pre>
|
592
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
592
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 484</span>
|
593
|
+
484: <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> )
|
594
|
+
485: <span class="ruby-comment cmt">#@@__ROUTES[route] = yield</span>
|
595
|
+
486: <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>[<span class="ruby-identifier">route</span>] = <span class="ruby-keyword kw">yield</span>
|
596
|
+
487: <span class="ruby-keyword kw">end</span>
|
597
597
|
</pre>
|
598
598
|
</div>
|
599
599
|
</div>
|
@@ -617,10 +617,10 @@ parameters (GET or POST)
|
|
617
617
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
618
618
|
<div class="method-source-code" id="M000002-source">
|
619
619
|
<pre>
|
620
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
621
|
-
|
622
|
-
|
623
|
-
|
620
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 347</span>
|
621
|
+
347: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
622
|
+
348: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
623
|
+
349: <span class="ruby-keyword kw">end</span>
|
624
624
|
</pre>
|
625
625
|
</div>
|
626
626
|
</div>
|
@@ -643,10 +643,10 @@ Return the Rack::Request object
|
|
643
643
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
644
644
|
<div class="method-source-code" id="M000005-source">
|
645
645
|
<pre>
|
646
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
647
|
-
|
648
|
-
|
649
|
-
|
646
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 362</span>
|
647
|
+
362: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
648
|
+
363: <span class="ruby-ivar">@request</span>
|
649
|
+
364: <span class="ruby-keyword kw">end</span>
|
650
650
|
</pre>
|
651
651
|
</div>
|
652
652
|
</div>
|
@@ -669,10 +669,10 @@ Return the Rack::Response object
|
|
669
669
|
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
670
670
|
<div class="method-source-code" id="M000006-source">
|
671
671
|
<pre>
|
672
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
673
|
-
|
674
|
-
|
675
|
-
|
672
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 367</span>
|
673
|
+
367: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
674
|
+
368: <span class="ruby-ivar">@response</span>
|
675
|
+
369: <span class="ruby-keyword kw">end</span>
|
676
676
|
</pre>
|
677
677
|
</div>
|
678
678
|
</div>
|
@@ -703,131 +703,131 @@ href="Capcode.html#M000012">set</a> globally
|
|
703
703
|
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
704
704
|
<div class="method-source-code" id="M000011-source">
|
705
705
|
<pre>
|
706
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
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
|
-
715: <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> }
|
817
|
-
716: }
|
818
|
-
717: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
819
|
-
718: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"</span>
|
820
|
-
719: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">WEBrick</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">></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>
|
821
|
-
720: <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> }
|
822
|
-
721: }
|
823
|
-
722: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"thin"</span>
|
824
|
-
723: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"</span>
|
825
|
-
724: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Thin</span>.<span class="ruby-identifier">run</span>( <span class="ruby-identifier">app</span>, {<span class="ruby-identifier">:Port</span> =<span class="ruby-operator">></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>
|
706
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 616</span>
|
707
|
+
616: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
708
|
+
617: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">args</span>)
|
709
|
+
618:
|
710
|
+
619: <span class="ruby-comment cmt"># Parse options</span>
|
711
|
+
620: <span class="ruby-identifier">opts</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
|
712
|
+
621: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"Usage: #{File.basename($0)} [options]"</span>
|
713
|
+
622: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
714
|
+
623: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Specific options:"</span>
|
715
|
+
624:
|
716
|
+
625: <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> ) {
|
717
|
+
626: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:console</span>, <span class="ruby-keyword kw">true</span>
|
718
|
+
627: }
|
719
|
+
628: <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>
|
720
|
+
629: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:host</span>, <span class="ruby-identifier">h</span>
|
721
|
+
630: }
|
722
|
+
631: <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>
|
723
|
+
632: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:port</span>, <span class="ruby-identifier">p</span>
|
724
|
+
633: }
|
725
|
+
634: <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>
|
726
|
+
635: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:daemonize</span>, <span class="ruby-identifier">d</span>
|
727
|
+
636: }
|
728
|
+
637: <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>
|
729
|
+
638: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:root</span>, <span class="ruby-identifier">w</span>
|
730
|
+
639: }
|
731
|
+
640: <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>
|
732
|
+
641: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:static</span>, <span class="ruby-identifier">r</span>
|
733
|
+
642: }
|
734
|
+
643:
|
735
|
+
644: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
736
|
+
645: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span>
|
737
|
+
646:
|
738
|
+
647: <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>
|
739
|
+
648: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
|
740
|
+
649: <span class="ruby-identifier">exit</span>
|
741
|
+
650: <span class="ruby-keyword kw">end</span>
|
742
|
+
651: <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>
|
743
|
+
652: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Capcode version #{Capcode::CAPCOD_VERION} (ruby v#{RUBY_VERSION})"</span>
|
744
|
+
653: <span class="ruby-identifier">exit</span>
|
745
|
+
654: <span class="ruby-keyword kw">end</span>
|
746
|
+
655: <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>
|
747
|
+
656: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:verbose</span>, <span class="ruby-keyword kw">true</span>
|
748
|
+
657: <span class="ruby-keyword kw">end</span>
|
749
|
+
658: <span class="ruby-keyword kw">end</span>
|
750
|
+
659:
|
751
|
+
660: <span class="ruby-keyword kw">begin</span>
|
752
|
+
661: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
753
|
+
662: <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>
|
754
|
+
663: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
755
|
+
664: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
756
|
+
665: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
757
|
+
666: <span class="ruby-keyword kw">end</span>
|
758
|
+
667:
|
759
|
+
668: <span class="ruby-comment cmt"># Run in the Working directory</span>
|
760
|
+
669: <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>)
|
761
|
+
670: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:root</span>) ) <span class="ruby-keyword kw">do</span>
|
762
|
+
671:
|
763
|
+
672: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
764
|
+
673: <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>
|
765
|
+
674: <span class="ruby-keyword kw">begin</span>
|
766
|
+
675: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
767
|
+
676: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:mongrel</span>
|
768
|
+
677: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
769
|
+
678: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
770
|
+
679: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">set</span> <span class="ruby-identifier">:server</span>, <span class="ruby-identifier">:webrick</span>
|
771
|
+
680: <span class="ruby-keyword kw">end</span>
|
772
|
+
681: <span class="ruby-keyword kw">end</span>
|
773
|
+
682:
|
774
|
+
683: <span class="ruby-comment cmt"># From rackup !!!</span>
|
775
|
+
684: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:daemonize</span>)
|
776
|
+
685: <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/java/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">RUBY_PLATFORM</span>).<span class="ruby-identifier">nil?</span>
|
777
|
+
686: <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>
|
778
|
+
687: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
779
|
+
688: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
780
|
+
689: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
781
|
+
690: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
782
|
+
691: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
783
|
+
692: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
784
|
+
693: <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>
|
785
|
+
694: <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>
|
786
|
+
695: <span class="ruby-keyword kw">else</span>
|
787
|
+
696: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
788
|
+
697: <span class="ruby-keyword kw">end</span>
|
789
|
+
698: <span class="ruby-keyword kw">else</span>
|
790
|
+
699: <span class="ruby-identifier">puts</span> <span class="ruby-node">"!! daemonize option unavailable on #{RUBY_PLATFORM} platform."</span>
|
791
|
+
700: <span class="ruby-keyword kw">end</span>
|
792
|
+
701:
|
793
|
+
702: <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>) }
|
794
|
+
703: <span class="ruby-identifier">at_exit</span> { <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:pid</span>)) }
|
795
|
+
704: <span class="ruby-keyword kw">end</span>
|
796
|
+
705:
|
797
|
+
706: <span class="ruby-identifier">app</span> = <span class="ruby-keyword kw">nil</span>
|
798
|
+
707: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
799
|
+
708: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>) { <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> ) }
|
800
|
+
709: <span class="ruby-keyword kw">else</span>
|
801
|
+
710: <span class="ruby-identifier">app</span> = <span class="ruby-identifier">application</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>)
|
802
|
+
711: <span class="ruby-keyword kw">end</span>
|
803
|
+
712: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">CommonLogger</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">app</span>, <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:log</span>)) )
|
804
|
+
713:
|
805
|
+
714: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:console</span>)
|
806
|
+
715: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"Run console..."</span>
|
807
|
+
716: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
|
808
|
+
717: <span class="ruby-identifier">exit</span>
|
809
|
+
718: <span class="ruby-keyword kw">end</span>
|
810
|
+
719:
|
811
|
+
720: <span class="ruby-comment cmt"># Start server</span>
|
812
|
+
721: <span class="ruby-keyword kw">case</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">:server</span>).<span class="ruby-identifier">to_s</span>
|
813
|
+
722: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
814
|
+
723: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"</span>
|
815
|
+
724: <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">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>
|
826
816
|
725: <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> }
|
827
817
|
726: }
|
828
|
-
727: <span class="ruby-keyword kw">
|
829
|
-
728:
|
830
|
-
729:
|
818
|
+
727: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
819
|
+
728: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"</span>
|
820
|
+
729: <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>
|
821
|
+
730: <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> }
|
822
|
+
731: }
|
823
|
+
732: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"thin"</span>
|
824
|
+
733: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Thin on #{Capcode::Configuration.get(:host)}:#{Capcode::Configuration.get(:port)}"</span>
|
825
|
+
734: <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>
|
826
|
+
735: <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> }
|
827
|
+
736: }
|
828
|
+
737: <span class="ruby-keyword kw">end</span>
|
829
|
+
738: <span class="ruby-keyword kw">end</span>
|
830
|
+
739: <span class="ruby-keyword kw">end</span>
|
831
831
|
</pre>
|
832
832
|
</div>
|
833
833
|
</div>
|
@@ -850,10 +850,10 @@ Session hash
|
|
850
850
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
851
851
|
<div class="method-source-code" id="M000004-source">
|
852
852
|
<pre>
|
853
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
854
|
-
|
855
|
-
|
856
|
-
|
853
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 357</span>
|
854
|
+
357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
855
|
+
358: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
856
|
+
359: <span class="ruby-keyword kw">end</span>
|
857
857
|
</pre>
|
858
858
|
</div>
|
859
859
|
</div>
|
@@ -909,10 +909,10 @@ Example :
|
|
909
909
|
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
910
910
|
<div class="method-source-code" id="M000008-source">
|
911
911
|
<pre>
|
912
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
913
|
-
|
914
|
-
|
915
|
-
|
912
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 499</span>
|
913
|
+
499: <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>)
|
914
|
+
500: <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>]
|
915
|
+
501: <span class="ruby-keyword kw">end</span>
|
916
916
|
</pre>
|
917
917
|
</div>
|
918
918
|
</div>
|