Capcode 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +5 -0
- data/doc/rdoc/classes/Capcode.html +289 -226
- data/doc/rdoc/classes/Capcode/Helpers.html +62 -62
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +15 -1
- data/doc/rdoc/files/lib/capcode_rb.html +3 -1
- data/examples/blog-couchdb.rb +107 -12
- data/examples/blog-dm.rb +0 -2
- data/examples/my_blog.db +0 -0
- data/lib/capcode.rb +73 -2
- data/lib/capcode/base/couchdb.rb +1 -4
- data/lib/capcode/base/dm.rb +1 -1
- data/lib/capcode/version.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -10,6 +10,11 @@ Capcode is a web microframework
|
|
10
10
|
|
11
11
|
== FEATURES/PROBLEMS:
|
12
12
|
|
13
|
+
=== 0.7.0
|
14
|
+
* You no more need to include Capcode::Resource in your models
|
15
|
+
* Capcode.run now accept a block. The content of the block is executed just before the server start.
|
16
|
+
* Add options support : you can now change the defaults port and host, daemonize or not and run in console mode.
|
17
|
+
|
13
18
|
=== 0.6.2
|
14
19
|
* Add Markaby, Erb and Haml layout see Capcode::Helpers.render for more informations
|
15
20
|
* Add content_for...
|
@@ -130,115 +130,130 @@ If the regexp in the route does not match, all arguments will be
|
|
130
130
|
<p class="source-link">[ <a href="javascript:toggleSource('M000001_source')" id="l_M000001_source">show source</a> ]</p>
|
131
131
|
<div id="M000001_source" class="dyn-source">
|
132
132
|
<pre>
|
133
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|
-
|
240
|
-
|
241
|
-
|
133
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 248</span>
|
134
|
+
248: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">u</span>
|
135
|
+
249: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
|
136
|
+
250: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>){
|
137
|
+
251: <span class="ruby-comment cmt"># < Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)'</span>
|
138
|
+
252: <span class="ruby-comment cmt"># # => [ {'/hello/world' => '([^\/]*)/id(\d*)', '/hello' => '(.*)'}, 2, <Capcode::Klass> ]</span>
|
139
|
+
253: <span class="ruby-identifier">h</span> = {}
|
140
|
+
254: <span class="ruby-identifier">max</span> = <span class="ruby-value">0</span>
|
141
|
+
255: <span class="ruby-identifier">u</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>
|
142
|
+
256: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">_u</span> )
|
143
|
+
257: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
144
|
+
258: <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 defined with regexp `#{h[_u]}' !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">h</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_u</span>)
|
145
|
+
259: <span class="ruby-identifier">h</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-value str">''</span>
|
146
|
+
260: <span class="ruby-keyword kw">else</span>
|
147
|
+
261: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
|
148
|
+
262: <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>
|
149
|
+
263: <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 `#{h[_pre]}' !"</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">h</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">_pre</span>)
|
150
|
+
264: <span class="ruby-identifier">h</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>]
|
151
|
+
265: <span class="ruby-identifier">max</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</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>
|
152
|
+
266: <span class="ruby-keyword kw">end</span>
|
153
|
+
267: <span class="ruby-keyword kw">end</span>
|
154
|
+
268: [<span class="ruby-identifier">h</span>, <span class="ruby-identifier">max</span>, <span class="ruby-keyword kw">self</span>]
|
155
|
+
269: }
|
156
|
+
270:
|
157
|
+
271: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
|
158
|
+
272: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
159
|
+
273: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
160
|
+
274: <span class="ruby-keyword kw">end</span>
|
161
|
+
275:
|
162
|
+
276: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
|
163
|
+
277: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
164
|
+
278: <span class="ruby-ivar">@env</span>
|
165
|
+
279: <span class="ruby-keyword kw">end</span>
|
166
|
+
280:
|
167
|
+
281: <span class="ruby-comment cmt"># Hash session</span>
|
168
|
+
282: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
169
|
+
283: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
170
|
+
284: <span class="ruby-keyword kw">end</span>
|
171
|
+
285:
|
172
|
+
286: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
|
173
|
+
287: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
174
|
+
288: <span class="ruby-ivar">@request</span>
|
175
|
+
289: <span class="ruby-keyword kw">end</span>
|
176
|
+
290:
|
177
|
+
291: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
|
178
|
+
292: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
179
|
+
293: <span class="ruby-ivar">@response</span>
|
180
|
+
294: <span class="ruby-keyword kw">end</span>
|
181
|
+
295:
|
182
|
+
296: <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>
|
183
|
+
297: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
|
184
|
+
298: <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>
|
185
|
+
299: <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>)
|
186
|
+
300:
|
187
|
+
301: <span class="ruby-comment cmt"># __k = self.class.to_s.split( /::/ )[-1].downcase.to_sym</span>
|
188
|
+
302: <span class="ruby-comment cmt"># @@__FILTERS.each do |f|</span>
|
189
|
+
303: <span class="ruby-comment cmt"># proc = f.delete(:action)</span>
|
190
|
+
304: <span class="ruby-comment cmt"># __run = true</span>
|
191
|
+
305: <span class="ruby-comment cmt"># if f[:only]</span>
|
192
|
+
306: <span class="ruby-comment cmt"># __run = f[:only].include?(__k)</span>
|
193
|
+
307: <span class="ruby-comment cmt"># end</span>
|
194
|
+
308: <span class="ruby-comment cmt"># if f[:except]</span>
|
195
|
+
309: <span class="ruby-comment cmt"># __run = !f[:except].include?(__k)</span>
|
196
|
+
310: <span class="ruby-comment cmt"># end</span>
|
197
|
+
311: <span class="ruby-comment cmt"># </span>
|
198
|
+
312: <span class="ruby-comment cmt"># # proc.call(self) if __run</span>
|
199
|
+
313: <span class="ruby-comment cmt"># puts "call #{proc} for #{__k}"</span>
|
200
|
+
314: <span class="ruby-comment cmt"># end</span>
|
201
|
+
315:
|
202
|
+
316: <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>]
|
203
|
+
317: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"GET"</span>
|
204
|
+
318: <span class="ruby-identifier">finalPath</span> = <span class="ruby-keyword kw">nil</span>
|
205
|
+
319: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-keyword kw">nil</span>
|
206
|
+
320: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-keyword kw">nil</span>
|
207
|
+
321:
|
208
|
+
322: <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> )
|
209
|
+
323: <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>
|
210
|
+
324: <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> )
|
211
|
+
325: <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>
|
212
|
+
326: <span class="ruby-identifier">diffArgs</span> = <span class="ruby-identifier">aPath</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">xPath</span>
|
213
|
+
327: <span class="ruby-identifier">diffNArgs</span> = <span class="ruby-identifier">diffArgs</span>.<span class="ruby-identifier">size</span>
|
214
|
+
328: <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>
|
215
|
+
329: <span class="ruby-identifier">finalPath</span> = <span class="ruby-identifier">p</span>
|
216
|
+
330: <span class="ruby-identifier">finalNArgs</span> = <span class="ruby-identifier">diffNArgs</span>
|
217
|
+
331: <span class="ruby-identifier">finalArgs</span> = <span class="ruby-identifier">diffArgs</span>
|
218
|
+
332: <span class="ruby-keyword kw">end</span>
|
219
|
+
333: <span class="ruby-keyword kw">end</span>
|
220
|
+
334:
|
221
|
+
335: <span class="ruby-keyword kw">end</span>
|
222
|
+
336:
|
223
|
+
337: <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>]
|
224
|
+
338: <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>] )
|
225
|
+
339: <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> ) )
|
226
|
+
340: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
227
|
+
341: <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>
|
228
|
+
342: <span class="ruby-keyword kw">else</span>
|
229
|
+
343: <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> }
|
230
|
+
344: <span class="ruby-keyword kw">end</span>
|
231
|
+
345:
|
232
|
+
346: <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>
|
233
|
+
347: <span class="ruby-identifier">args</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">nil</span>
|
234
|
+
348: <span class="ruby-keyword kw">end</span>
|
235
|
+
349:
|
236
|
+
350: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
|
237
|
+
351: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"POST"</span>
|
238
|
+
352: <span class="ruby-identifier">post</span>
|
239
|
+
353: <span class="ruby-keyword kw">end</span>
|
240
|
+
354: <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>)
|
241
|
+
355: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
|
242
|
+
356: <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>
|
243
|
+
357: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
244
|
+
358: <span class="ruby-keyword kw">end</span>
|
245
|
+
359: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
|
246
|
+
360: <span class="ruby-keyword kw">else</span>
|
247
|
+
361: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
|
248
|
+
362: <span class="ruby-keyword kw">end</span>
|
249
|
+
363:
|
250
|
+
364: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
|
251
|
+
365: <span class="ruby-keyword kw">end</span>
|
252
|
+
366:
|
253
|
+
367: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
|
254
|
+
368: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Views</span>
|
255
|
+
369: }
|
256
|
+
370: <span class="ruby-keyword kw">end</span>
|
242
257
|
</pre>
|
243
258
|
</div>
|
244
259
|
</div>
|
@@ -253,10 +268,10 @@ Hash containing all the environment variables
|
|
253
268
|
<p class="source-link">[ <a href="javascript:toggleSource('M000003_source')" id="l_M000003_source">show source</a> ]</p>
|
254
269
|
<div id="M000003_source" class="dyn-source">
|
255
270
|
<pre>
|
256
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
257
|
-
|
258
|
-
|
259
|
-
|
271
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 277</span>
|
272
|
+
277: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
|
273
|
+
278: <span class="ruby-ivar">@env</span>
|
274
|
+
279: <span class="ruby-keyword kw">end</span>
|
260
275
|
</pre>
|
261
276
|
</div>
|
262
277
|
</div>
|
@@ -277,10 +292,10 @@ Rack or What you want Helper
|
|
277
292
|
<p class="source-link">[ <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show source</a> ]</p>
|
278
293
|
<div id="M000007_source" class="dyn-source">
|
279
294
|
<pre>
|
280
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
281
|
-
|
282
|
-
|
283
|
-
|
295
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 377</span>
|
296
|
+
377: <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> )
|
297
|
+
378: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
|
298
|
+
379: <span class="ruby-keyword kw">end</span>
|
284
299
|
</pre>
|
285
300
|
</div>
|
286
301
|
</div>
|
@@ -296,10 +311,10 @@ parameters (GET or POST)
|
|
296
311
|
<p class="source-link">[ <a href="javascript:toggleSource('M000002_source')" id="l_M000002_source">show source</a> ]</p>
|
297
312
|
<div id="M000002_source" class="dyn-source">
|
298
313
|
<pre>
|
299
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
300
|
-
|
301
|
-
|
302
|
-
|
314
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 272</span>
|
315
|
+
272: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
316
|
+
273: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
|
317
|
+
274: <span class="ruby-keyword kw">end</span>
|
303
318
|
</pre>
|
304
319
|
</div>
|
305
320
|
</div>
|
@@ -314,10 +329,10 @@ Return the Rack::Request object
|
|
314
329
|
<p class="source-link">[ <a href="javascript:toggleSource('M000005_source')" id="l_M000005_source">show source</a> ]</p>
|
315
330
|
<div id="M000005_source" class="dyn-source">
|
316
331
|
<pre>
|
317
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
318
|
-
|
319
|
-
|
320
|
-
|
332
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 287</span>
|
333
|
+
287: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
|
334
|
+
288: <span class="ruby-ivar">@request</span>
|
335
|
+
289: <span class="ruby-keyword kw">end</span>
|
321
336
|
</pre>
|
322
337
|
</div>
|
323
338
|
</div>
|
@@ -332,15 +347,15 @@ Return the Rack::Response object
|
|
332
347
|
<p class="source-link">[ <a href="javascript:toggleSource('M000006_source')" id="l_M000006_source">show source</a> ]</p>
|
333
348
|
<div id="M000006_source" class="dyn-source">
|
334
349
|
<pre>
|
335
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
336
|
-
|
337
|
-
|
338
|
-
|
350
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 292</span>
|
351
|
+
292: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
|
352
|
+
293: <span class="ruby-ivar">@response</span>
|
353
|
+
294: <span class="ruby-keyword kw">end</span>
|
339
354
|
</pre>
|
340
355
|
</div>
|
341
356
|
</div>
|
342
357
|
<h4 class="ruled">Public Class method:
|
343
|
-
<strong><a name="M000008">run( args = {} )</a></strong> <a href="#M000008"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: run" /></a></h4>
|
358
|
+
<strong><a name="M000008">run( args = {} ) {|self| ...}</a></strong> <a href="#M000008"><img src="../permalink.gif" border="0" title="Permalink to Public Class method: run" /></a></h4>
|
344
359
|
|
345
360
|
<p>
|
346
361
|
Start your application.
|
@@ -388,99 +403,147 @@ main.rb)
|
|
388
403
|
<p class="source-link">[ <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show source</a> ]</p>
|
389
404
|
<div id="M000008_source" class="dyn-source">
|
390
405
|
<pre>
|
391
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
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
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
437: <span class="ruby-keyword kw">end</span>
|
459
|
-
438:
|
460
|
-
439: <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>) }
|
461
|
-
440: <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>]) }
|
462
|
-
441: <span class="ruby-keyword kw">end</span>
|
463
|
-
442:
|
464
|
-
443: <span class="ruby-comment cmt"># Start database</span>
|
465
|
-
444: <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>
|
466
|
-
445: <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>] )
|
467
|
-
446: <span class="ruby-keyword kw">end</span>
|
468
|
-
447:
|
469
|
-
448: <span class="ruby-comment cmt"># Start server</span>
|
470
|
-
449: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
471
|
-
450: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
472
|
-
451: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
473
|
-
452: <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>
|
474
|
-
453: <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> }
|
475
|
-
454: }
|
476
|
-
455: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
477
|
-
456: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
478
|
-
457: <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>
|
479
|
-
458: <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> }
|
480
|
-
459: }
|
406
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 394</span>
|
407
|
+
394: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
|
408
|
+
395: <span class="ruby-identifier">conf</span> = {
|
409
|
+
396: <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>,
|
410
|
+
397: <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>,
|
411
|
+
398: <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>,
|
412
|
+
399: <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>,
|
413
|
+
400: <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>{},
|
414
|
+
401: <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>,
|
415
|
+
402: <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>,
|
416
|
+
403: <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>,
|
417
|
+
404: <span class="ruby-identifier">:root</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:root</span>]<span class="ruby-operator">||</span><span class="ruby-value str">"."</span>,
|
418
|
+
405: <span class="ruby-identifier">:working_directory</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:working_directory</span>]<span class="ruby-operator">||</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">$0</span>)),
|
419
|
+
406:
|
420
|
+
407: <span class="ruby-identifier">:console</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>
|
421
|
+
408: }
|
422
|
+
409:
|
423
|
+
410: <span class="ruby-comment cmt"># Parse options</span>
|
424
|
+
411: <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>
|
425
|
+
412: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"Usage: #{File.basename($0)} [options]"</span>
|
426
|
+
413: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
427
|
+
414: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Specific options:"</span>
|
428
|
+
415:
|
429
|
+
416: <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> ) {
|
430
|
+
417: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>] = <span class="ruby-keyword kw">true</span>
|
431
|
+
418: }
|
432
|
+
419: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-h"</span>, <span class="ruby-value str">"--host HOSTNAME"</span>, <span class="ruby-node">"Host for web server to bind to (default: #{conf[:host]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
433
|
+
420: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-identifier">h</span>
|
434
|
+
421: }
|
435
|
+
422: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-p"</span>, <span class="ruby-value str">"--port NUM"</span>, <span class="ruby-node">"Port for web server (default: #{conf[:port]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
436
|
+
423: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">p</span>
|
437
|
+
424: }
|
438
|
+
425: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on</span>( <span class="ruby-value str">"-d"</span>, <span class="ruby-value str">"--daemonize [true|false]"</span>, <span class="ruby-node">"Daemonize (default: #{conf[:daemonize]})"</span> ) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
|
439
|
+
426: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>] = <span class="ruby-identifier">d</span>
|
440
|
+
427: }
|
441
|
+
428:
|
442
|
+
429: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">""</span>
|
443
|
+
430: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">separator</span> <span class="ruby-value str">"Common options:"</span>
|
444
|
+
431:
|
445
|
+
432: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">on_tail</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>
|
446
|
+
433: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opts</span>
|
447
|
+
434: <span class="ruby-identifier">exit</span>
|
448
|
+
435: <span class="ruby-keyword kw">end</span>
|
449
|
+
436: <span class="ruby-keyword kw">end</span>
|
450
|
+
437:
|
451
|
+
438: <span class="ruby-keyword kw">begin</span>
|
452
|
+
439: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-constant">ARGV</span>
|
453
|
+
440: <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>
|
454
|
+
441: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">"!! #{ex.message}"</span>
|
455
|
+
442: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** use `#{File.basename($0)} --help` for more details..."</span>
|
456
|
+
443: <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
|
457
|
+
444: <span class="ruby-keyword kw">end</span>
|
458
|
+
445:
|
459
|
+
446: <span class="ruby-comment cmt"># Run in the Working directory</span>
|
460
|
+
447: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:working_directory</span>] ) <span class="ruby-keyword kw">do</span>
|
461
|
+
448: <span class="ruby-comment cmt"># Set root directory for helpers</span>
|
462
|
+
449: <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">root</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>( <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>] )
|
463
|
+
450:
|
464
|
+
451: <span class="ruby-comment cmt"># Check that mongrel exists </span>
|
465
|
+
452: <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>
|
466
|
+
453: <span class="ruby-keyword kw">begin</span>
|
467
|
+
454: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
|
468
|
+
455: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"mongrel"</span>
|
469
|
+
456: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
|
470
|
+
457: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"!! could not load mongrel. Falling back to webrick."</span>
|
471
|
+
458: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">"webrick"</span>
|
472
|
+
459: <span class="ruby-keyword kw">end</span>
|
481
473
|
460: <span class="ruby-keyword kw">end</span>
|
482
|
-
461:
|
483
|
-
462:
|
474
|
+
461:
|
475
|
+
462: <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>
|
476
|
+
463: <span class="ruby-keyword kw">begin</span>
|
477
|
+
464: <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>
|
478
|
+
465: <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>
|
479
|
+
466: <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>
|
480
|
+
467: <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>)
|
481
|
+
468: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
|
482
|
+
469: <span class="ruby-keyword kw">end</span>
|
483
|
+
470: <span class="ruby-keyword kw">end</span>
|
484
|
+
471: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
485
|
+
472: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
486
|
+
473: <span class="ruby-keyword kw">end</span>
|
487
|
+
474: <span class="ruby-keyword kw">end</span>
|
488
|
+
475:
|
489
|
+
476: <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>)
|
490
|
+
477: <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>] )
|
491
|
+
478: <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>, <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:root</span>])
|
492
|
+
479: <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>)
|
493
|
+
480: <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>)
|
494
|
+
481: <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>)
|
495
|
+
482: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
|
496
|
+
483: <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>]) )
|
497
|
+
484:
|
498
|
+
485: <span class="ruby-comment cmt"># From rackup !!!</span>
|
499
|
+
486: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
|
500
|
+
487: <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>
|
501
|
+
488: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
502
|
+
489: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
503
|
+
490: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
504
|
+
491: <span class="ruby-comment cmt"># Dir.chdir "/"</span>
|
505
|
+
492: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
506
|
+
493: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
507
|
+
494: <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>
|
508
|
+
495: <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>
|
509
|
+
496: <span class="ruby-keyword kw">else</span>
|
510
|
+
497: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
|
511
|
+
498: <span class="ruby-keyword kw">end</span>
|
512
|
+
499:
|
513
|
+
500: <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>) }
|
514
|
+
501: <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>]) }
|
515
|
+
502: <span class="ruby-keyword kw">end</span>
|
516
|
+
503:
|
517
|
+
504: <span class="ruby-comment cmt"># Start database</span>
|
518
|
+
505: <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>
|
519
|
+
506: <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>] )
|
520
|
+
507: <span class="ruby-keyword kw">end</span>
|
521
|
+
508:
|
522
|
+
509: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
523
|
+
510: <span class="ruby-keyword kw">yield</span>( <span class="ruby-keyword kw">self</span> )
|
524
|
+
511: <span class="ruby-keyword kw">end</span>
|
525
|
+
512:
|
526
|
+
513: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:console</span>]
|
527
|
+
514: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"Run console..."</span>
|
528
|
+
515: <span class="ruby-constant">IRB</span>.<span class="ruby-identifier">start</span>
|
529
|
+
516: <span class="ruby-identifier">exit</span>
|
530
|
+
517: <span class="ruby-keyword kw">end</span>
|
531
|
+
518:
|
532
|
+
519: <span class="ruby-comment cmt"># Start server</span>
|
533
|
+
520: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
|
534
|
+
521: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"mongrel"</span>
|
535
|
+
522: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"</span>
|
536
|
+
523: <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>
|
537
|
+
524: <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> }
|
538
|
+
525: }
|
539
|
+
526: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"webrick"</span>
|
540
|
+
527: <span class="ruby-identifier">puts</span> <span class="ruby-node">"** Starting WEBrick on #{conf[:host]}:#{conf[:port]}"</span>
|
541
|
+
528: <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>
|
542
|
+
529: <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> }
|
543
|
+
530: }
|
544
|
+
531: <span class="ruby-keyword kw">end</span>
|
545
|
+
532: <span class="ruby-keyword kw">end</span>
|
546
|
+
533: <span class="ruby-keyword kw">end</span>
|
484
547
|
</pre>
|
485
548
|
</div>
|
486
549
|
</div>
|
@@ -495,10 +558,10 @@ Hash <a href="Capcode.html#M000004">session</a>
|
|
495
558
|
<p class="source-link">[ <a href="javascript:toggleSource('M000004_source')" id="l_M000004_source">show source</a> ]</p>
|
496
559
|
<div id="M000004_source" class="dyn-source">
|
497
560
|
<pre>
|
498
|
-
<span class="ruby-comment cmt"># File lib/capcode.rb, line
|
499
|
-
|
500
|
-
|
501
|
-
|
561
|
+
<span class="ruby-comment cmt"># File lib/capcode.rb, line 282</span>
|
562
|
+
282: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
|
563
|
+
283: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
|
564
|
+
284: <span class="ruby-keyword kw">end</span>
|
502
565
|
</pre>
|
503
566
|
</div>
|
504
567
|
</div>
|