Capcode 0.2.0 → 0.3.0
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 +3 -0
- data/doc/rdoc/classes/Capcode.html +147 -125
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +7 -1
- data/doc/rdoc/files/lib/capcode_rb.html +1 -1
- data/lib/capcode.rb +26 -4
- data/lib/capcode/version.rb +1 -1
- metadata +6 -11
data/README
CHANGED
@@ -183,42 +183,64 @@ If the regexp in the route does not match, all arguments will be
|
|
183
183
|
182:
|
184
184
|
183: <span class="ruby-identifier">r</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>]
|
185
185
|
184: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
186
|
-
185: <span class="ruby-identifier">
|
187
|
-
186: <span class="ruby-identifier">
|
188
|
-
187: <span class="ruby-identifier">
|
189
|
-
188:
|
190
|
-
189:
|
191
|
-
190: <span class="ruby-
|
192
|
-
191:
|
193
|
-
192: <span class="ruby-
|
194
|
-
193:
|
195
|
-
194:
|
196
|
-
195:
|
197
|
-
196:
|
198
|
-
197:
|
199
|
-
198:
|
200
|
-
199:
|
201
|
-
200:
|
202
|
-
201:
|
203
|
-
202:
|
204
|
-
203:
|
205
|
-
204:
|
206
|
-
205:
|
207
|
-
206:
|
208
|
-
207:
|
209
|
-
208:
|
210
|
-
209:
|
211
|
-
210:
|
212
|
-
211:
|
213
|
-
212:
|
214
|
-
213:
|
215
|
-
214:
|
216
|
-
215:
|
217
|
-
216:
|
218
|
-
217:
|
219
|
-
218:
|
220
|
-
219:
|
221
|
-
220:
|
186
|
+
185: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
187
|
+
186: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
188
|
+
187: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
189
|
+
188:
|
190
|
+
189: <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> )
|
191
|
+
190: <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>
|
192
|
+
191: <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> )
|
193
|
+
192: <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>
|
194
|
+
193: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
195
|
+
194: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
|
196
|
+
195: <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>
|
197
|
+
196: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
198
|
+
197: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
199
|
+
198: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
200
|
+
199: <span class="ruby-keyword kw">end</span>
|
201
|
+
200: <span class="ruby-keyword kw">end</span>
|
202
|
+
201:
|
203
|
+
202: <span class="ruby-keyword kw">end</span>
|
204
|
+
203:
|
205
|
+
204: <span class="ruby-comment cmt"># TODO : correct above to use this :</span>
|
206
|
+
205: <span class="ruby-comment cmt">#puts "finalPath = #{finalPath}"</span>
|
207
|
+
206: <span class="ruby-comment cmt">#puts "finalNArgs = #{finalNArgs}"</span>
|
208
|
+
207: <span class="ruby-comment cmt">#print "finalArgs = "; p finalArgs</span>
|
209
|
+
208:
|
210
|
+
209: <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>]
|
211
|
+
210: <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>] )
|
212
|
+
211:
|
213
|
+
212: <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_info</span>).<span class="ruby-identifier">gsub</span>( <span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">""</span> ) )
|
214
|
+
213: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
215
|
+
214: <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>
|
216
|
+
215: <span class="ruby-keyword kw">else</span>
|
217
|
+
216: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>
|
218
|
+
217: <span class="ruby-keyword kw">end</span>
|
219
|
+
218:
|
220
|
+
219: <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>
|
221
|
+
220: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
222
|
+
221: <span class="ruby-keyword kw">end</span>
|
223
|
+
222:
|
224
|
+
223: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
225
|
+
224: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
226
|
+
225: <span class="ruby-identifier">post</span>
|
227
|
+
226: <span class="ruby-keyword kw">end</span>
|
228
|
+
227: <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>)
|
229
|
+
228: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
|
230
|
+
229: <span class="ruby-identifier">r</span>[<span class="ruby-value">1</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>
|
231
|
+
230: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
232
|
+
231: <span class="ruby-keyword kw">end</span>
|
233
|
+
232: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
|
234
|
+
233: <span class="ruby-keyword kw">else</span>
|
235
|
+
234: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
236
|
+
235: <span class="ruby-keyword kw">end</span>
|
237
|
+
236:
|
238
|
+
237: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
239
|
+
238: <span class="ruby-keyword kw">end</span>
|
240
|
+
239:
|
241
|
+
240: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
242
|
+
241: }
|
243
|
+
242: <span class="ruby-keyword kw">end</span>
|
222
244
|
</pre>
|
223
245
|
</div>
|
224
246
|
</div>
|
@@ -257,10 +279,10 @@ Rack or What you want Helper
|
|
257
279
|
<p class="source-link">[ <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show source</a> ]</p>
|
258
280
|
<div id="M000007_source" class="dyn-source">
|
259
281
|
<pre>
|
260
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
261
|
-
|
262
|
-
|
263
|
-
|
282
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 249</span>
|
283
|
+
249: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">r</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span> )
|
284
|
+
250: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
|
285
|
+
251: <span class="ruby-keyword kw">end</span>
|
264
286
|
</pre>
|
265
287
|
</div>
|
266
288
|
</div>
|
@@ -357,91 +379,91 @@ See Rack::Session for more informations
|
|
357
379
|
<p class="source-link">[ <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show source</a> ]</p>
|
358
380
|
<div id="M000008_source" class="dyn-source">
|
359
381
|
<pre>
|
360
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
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
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
382
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 263</span>
|
383
|
+
263: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
384
|
+
264: <span class="ruby-identifier">conf</span> = {
|
385
|
+
265: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:port</span>]<span class="ruby-operator">||</span><span class="ruby-value">3000</span>,
|
386
|
+
266: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:host</span>]<span class="ruby-operator">||</span><span class="ruby-value str">"localhost"</span>,
|
387
|
+
267: <span class="ruby-identifier">:server</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:server</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">nil</span>,
|
388
|
+
268: <span class="ruby-identifier">:log</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:log</span>]<span class="ruby-operator">||</span><span class="ruby-identifier">$stdout</span>,
|
389
|
+
269: <span class="ruby-identifier">:session</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:session</span>]<span class="ruby-operator">||</span>{},
|
390
|
+
270: <span class="ruby-identifier">:pid</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:pid</span>]<span class="ruby-operator">||</span><span class="ruby-node">"#{$0}.pid"</span>,
|
391
|
+
271: <span class="ruby-identifier">:daemonize</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:daemonize</span>]<span class="ruby-operator">||</span><span class="ruby-keyword kw">false</span>,
|
392
|
+
272: <span class="ruby-identifier">:db_config</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:db_config</span>]<span class="ruby-operator">||</span><span class="ruby-value str">"database.yml"</span>
|
393
|
+
273: }
|
394
|
+
274:
|
395
|
+
275: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
396
|
+
276: <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>
|
397
|
+
277: <span class="ruby-keyword kw">begin</span>
|
398
|
+
278: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
399
|
+
279: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"mongrel"</span>
|
400
|
+
280: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
401
|
+
281: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
402
|
+
282: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"webrick"</span>
|
403
|
+
283: <span class="ruby-keyword kw">end</span>
|
404
|
+
284: <span class="ruby-keyword kw">end</span>
|
405
|
+
285:
|
406
|
+
286: <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>
|
407
|
+
287: <span class="ruby-keyword kw">begin</span>
|
408
|
+
288: <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>
|
409
|
+
289: <span class="ruby-identifier">u</span>, <span class="ruby-identifier">m</span>, <span class="ruby-identifier">c</span> = <span class="ruby-identifier">eval</span> <span class="ruby-node">"Capcode::#{k}.__urls__"</span>
|
410
|
+
290: <span class="ruby-identifier">u</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">_u</span><span class="ruby-operator">|</span>
|
411
|
+
291: <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 `#{_u}' already define !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@__ROUTES</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_u</span>)
|
412
|
+
292: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
|
413
|
+
293: <span class="ruby-keyword kw">end</span>
|
414
|
+
294: <span class="ruby-keyword kw">end</span>
|
415
|
+
295: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
416
|
+
296: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
417
|
+
297: <span class="ruby-keyword kw">end</span>
|
418
|
+
298: <span class="ruby-keyword kw">end</span>
|
419
|
+
299:
|
420
|
+
300: <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-ivar">@@__ROUTES</span>)
|
421
|
+
301: <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>] )
|
422
|
+
302: <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>)
|
423
|
+
303: <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>)
|
424
|
+
304: <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>)
|
425
|
+
305: <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>)
|
426
|
+
306: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
427
|
+
307: <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>]) )
|
428
|
+
308:
|
429
|
+
309: <span class="ruby-comment cmt"># From rackup !!!</span>
|
430
|
+
310: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
|
431
|
+
311: <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>
|
432
|
+
312: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
433
|
+
313: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
434
|
+
314: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
435
|
+
315: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
436
|
+
316: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
437
|
+
317: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
438
|
+
318: <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>
|
439
|
+
319: <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>
|
440
|
+
320: <span class="ruby-keyword kw">else</span>
|
441
|
+
321: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
442
|
+
322: <span class="ruby-keyword kw">end</span>
|
443
|
+
323:
|
444
|
+
324: <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>) }
|
445
|
+
325: <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>]) }
|
446
|
+
326: <span class="ruby-keyword kw">end</span>
|
447
|
+
327:
|
448
|
+
328: <span class="ruby-comment cmt"># Start database</span>
|
449
|
+
329: <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>
|
450
|
+
330: <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>] )
|
451
|
+
331: <span class="ruby-keyword kw">end</span>
|
452
|
+
332:
|
453
|
+
333: <span class="ruby-comment cmt"># Start server</span>
|
454
|
+
334: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
455
|
+
335: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
456
|
+
336: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
457
|
+
337: <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>
|
458
|
+
338: <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> }
|
459
|
+
339: }
|
460
|
+
340: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
461
|
+
341: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
462
|
+
342: <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>
|
463
|
+
343: <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> }
|
464
|
+
344: }
|
465
|
+
345: <span class="ruby-keyword kw">end</span>
|
466
|
+
346: <span class="ruby-keyword kw">end</span>
|
445
467
|
</pre>
|
446
468
|
</div>
|
447
469
|
</div>
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Wed, 29 Apr 2009 18:55:19 +0200
|
data/doc/rdoc/files/README.html
CHANGED
@@ -79,7 +79,7 @@ end</strong>
|
|
79
79
|
<div id="README" class="page_shade">
|
80
80
|
<div class="page">
|
81
81
|
<div class="header">
|
82
|
-
<div class="path">README /
|
82
|
+
<div class="path">README / Wed Apr 29 18:53:54 +0200 2009</div>
|
83
83
|
</div>
|
84
84
|
|
85
85
|
<h1><a href="../classes/Capcode.html">Capcode</a></h1>
|
@@ -96,6 +96,12 @@ Copyright (C) 2009 Gregoire Lejeune
|
|
96
96
|
<a href="../classes/Capcode.html">Capcode</a> is a web microframework
|
97
97
|
</p>
|
98
98
|
<h2>FEATURES/PROBLEMS:</h2>
|
99
|
+
<h3>0.3.0</h3>
|
100
|
+
<ul>
|
101
|
+
<li>Work with Rack 1.0.0
|
102
|
+
|
103
|
+
</li>
|
104
|
+
</ul>
|
99
105
|
<h3>0.2.0</h3>
|
100
106
|
<ul>
|
101
107
|
<li>Add models with DataMapper and couch_foo
|
@@ -79,7 +79,7 @@ end</strong>
|
|
79
79
|
<div id="lib/capcode.rb" class="page_shade">
|
80
80
|
<div class="page">
|
81
81
|
<div class="header">
|
82
|
-
<div class="path">lib/capcode.rb /
|
82
|
+
<div class="path">lib/capcode.rb / Wed Apr 29 18:52:03 +0200 2009</div>
|
83
83
|
</div>
|
84
84
|
|
85
85
|
<pre>
|
data/lib/capcode.rb
CHANGED
@@ -101,7 +101,7 @@ module Capcode
|
|
101
101
|
status, headers, body = @app.call(env)
|
102
102
|
|
103
103
|
if self.methods.include? "r#{status}"
|
104
|
-
body = self.
|
104
|
+
body = self.send( "r#{status}", env['REQUEST_PATH'] )
|
105
105
|
headers['Content-Length'] = body.length.to_s
|
106
106
|
end
|
107
107
|
|
@@ -182,10 +182,32 @@ module Capcode
|
|
182
182
|
|
183
183
|
r = case @env["REQUEST_METHOD"]
|
184
184
|
when "GET"
|
185
|
-
|
186
|
-
|
187
|
-
|
185
|
+
finalPath = nil
|
186
|
+
finalArgs = nil
|
187
|
+
finalNArgs = nil
|
188
|
+
|
189
|
+
aPath = @request.path.gsub( /^\//, "" ).split( "/" )
|
190
|
+
self.class.__urls__[0].each do |p, r|
|
191
|
+
xPath = p.gsub( /^\//, "" ).split( "/" )
|
192
|
+
if (xPath - aPath).size == 0
|
193
|
+
diffArgs = aPath - xPath
|
194
|
+
diffNArgs = diffArgs.size
|
195
|
+
if finalNArgs.nil? or finalNArgs > diffNArgs
|
196
|
+
finalPath = p
|
197
|
+
finalNArgs = diffNArgs
|
198
|
+
finalArgs = diffArgs
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
# TODO : correct above to use this :
|
205
|
+
#puts "finalPath = #{finalPath}"
|
206
|
+
#puts "finalNArgs = #{finalNArgs}"
|
207
|
+
#print "finalArgs = "; p finalArgs
|
208
|
+
|
188
209
|
nargs = self.class.__urls__[1]
|
210
|
+
regexp = Regexp.new( self.class.__urls__[0][finalPath] )
|
189
211
|
|
190
212
|
args = regexp.match( Rack::Utils.unescape(@request.path_info).gsub( /^\//, "" ) )
|
191
213
|
if args.nil?
|
data/lib/capcode/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Capcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Gr\xC3\xA9goire Lejeune"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-29 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,27 +38,20 @@ files:
|
|
38
38
|
- README
|
39
39
|
- AUTHORS
|
40
40
|
- setup.rb
|
41
|
-
- doc/rdoc
|
42
|
-
- doc/rdoc/classes
|
43
|
-
- doc/rdoc/classes/Capcode
|
44
41
|
- doc/rdoc/classes/Capcode/Helpers.html
|
45
42
|
- doc/rdoc/classes/Capcode/HTTPError.html
|
46
43
|
- doc/rdoc/classes/Capcode/ParameterError.html
|
47
44
|
- doc/rdoc/classes/Capcode/RouteError.html
|
48
45
|
- doc/rdoc/classes/Capcode.html
|
49
46
|
- doc/rdoc/created.rid
|
50
|
-
- doc/rdoc/files
|
51
47
|
- doc/rdoc/files/AUTHORS.html
|
52
48
|
- doc/rdoc/files/COPYING.html
|
53
|
-
- doc/rdoc/files/lib
|
54
49
|
- doc/rdoc/files/lib/capcode_rb.html
|
55
50
|
- doc/rdoc/files/README.html
|
56
51
|
- doc/rdoc/index.html
|
57
52
|
- doc/rdoc/permalink.gif
|
58
53
|
- doc/rdoc/rdoc-style.css
|
59
54
|
- doc/rdoc/rubyfr.png
|
60
|
-
- lib/capcode
|
61
|
-
- lib/capcode/base
|
62
55
|
- lib/capcode/base/couchdb.rb
|
63
56
|
- lib/capcode/base/dm.rb
|
64
57
|
- lib/capcode/core_ext.rb
|
@@ -74,6 +67,8 @@ files:
|
|
74
67
|
- examples/session.rb
|
75
68
|
has_rdoc: true
|
76
69
|
homepage: http://algorithmique.net
|
70
|
+
licenses: []
|
71
|
+
|
77
72
|
post_install_message: |-
|
78
73
|
For more information about Capcode,
|
79
74
|
see http://capcode.rubyforge.org
|
@@ -106,9 +101,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
101
|
requirements: []
|
107
102
|
|
108
103
|
rubyforge_project: capcode
|
109
|
-
rubygems_version: 1.3.
|
104
|
+
rubygems_version: 1.3.2
|
110
105
|
signing_key:
|
111
|
-
specification_version:
|
106
|
+
specification_version: 3
|
112
107
|
summary: Capcode is a web microframework
|
113
108
|
test_files: []
|
114
109
|
|