Capcode 0.1.0 → 0.2.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 CHANGED
@@ -10,6 +10,11 @@ Capcode is a web microframework
10
10
 
11
11
  == FEATURES/PROBLEMS:
12
12
 
13
+ === 0.2.0
14
+ * Add models with DataMapper and couch_foo
15
+ * Add two new options : :daemonize and :pid
16
+ * Bug correction in Route.
17
+
13
18
  === 0.1.0
14
19
  * First public release
15
20
  * No models !!!
@@ -35,6 +40,23 @@ Capcode is a web microframework
35
40
  * Run: <tt>ruby sample.rb</tt>
36
41
  * Visit http://localhost:3000/
37
42
 
43
+ == Create model
44
+
45
+ require 'rubygems'
46
+ require 'capcode'
47
+ require 'capcode/base/dm' # or require 'capcode/base/couchdb'
48
+
49
+ class Story < Capcode::Base
50
+ include Capcode::Resource
51
+
52
+ property :id, Integer, :serial => true # only with DataMapper !
53
+ property :title, String
54
+ property :body, String
55
+ property :date, String
56
+ end
57
+
58
+ See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt> for complete examples.
59
+
38
60
  == REQUIREMENTS:
39
61
 
40
62
  * rack
@@ -68,6 +68,7 @@
68
68
  <a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
69
69
  <a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
70
70
  <a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
71
+ <a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
71
72
  <a href="../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
72
73
  end</strong>
73
74
  </td></tr>
@@ -126,94 +127,98 @@ If the regexp in the route does not match, all arguments will be
126
127
  <p class="source-link">[ <a href="javascript:toggleSource('M000001_source')" id="l_M000001_source">show source</a> ]</p>
127
128
  <div id="M000001_source" class="dyn-source">
128
129
  <pre>
129
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 127</span>
130
- 127: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">u</span>
131
- 128: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
132
- 129: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>){
133
- 130: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)'</span>
134
- 131: <span class="ruby-comment cmt"># # =&gt; [ {'/hello/world' =&gt; '([^\/]*)/id(\d*)', '/hello' =&gt; '(.*)'}, 2, &lt;Capcode::Klass&gt; ]</span>
135
- 132: <span class="ruby-identifier">h</span> = {}
136
- 133: <span class="ruby-identifier">max</span> = <span class="ruby-value">0</span>
137
- 134: <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>
138
- 135: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">_u</span> )
139
- 136: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
140
- 137: <span class="ruby-identifier">h</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-value str">''</span>
141
- 138: <span class="ruby-keyword kw">else</span>
142
- 139: <span class="ruby-identifier">h</span>[<span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>] = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>[<span class="ruby-value">0</span>]
143
- 140: <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">&lt;</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>
144
- 141: <span class="ruby-keyword kw">end</span>
145
- 142: <span class="ruby-keyword kw">end</span>
146
- 143: [<span class="ruby-identifier">h</span>, <span class="ruby-identifier">max</span>, <span class="ruby-keyword kw">self</span>]
147
- 144: }
148
- 145:
149
- 146: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
150
- 147: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
151
- 148: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
152
- 149: <span class="ruby-keyword kw">end</span>
153
- 150:
154
- 151: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
155
- 152: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
156
- 153: <span class="ruby-ivar">@env</span>
157
- 154: <span class="ruby-keyword kw">end</span>
158
- 155:
159
- 156: <span class="ruby-comment cmt"># Hash session</span>
160
- 157: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
161
- 158: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
162
- 159: <span class="ruby-keyword kw">end</span>
163
- 160:
164
- 161: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
165
- 162: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
166
- 163: <span class="ruby-ivar">@request</span>
167
- 164: <span class="ruby-keyword kw">end</span>
168
- 165:
169
- 166: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
170
- 167: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
171
- 168: <span class="ruby-ivar">@response</span>
172
- 169: <span class="ruby-keyword kw">end</span>
173
- 170:
174
- 171: <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>
175
- 172: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
176
- 173: <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>
177
- 174: <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>)
178
- 175:
179
- 176: <span class="ruby-identifier">r</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@env</span>[<span class="ruby-value str">&quot;REQUEST_METHOD&quot;</span>]
180
- 177: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;GET&quot;</span>
181
- 178: <span class="ruby-identifier">sc</span> = <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">script_name</span>
182
- 179: <span class="ruby-identifier">sc</span> = <span class="ruby-value str">&quot;/&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sc</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
183
- 180: <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">sc</span>] )
184
- 181: <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>]
185
- 182:
186
- 183: <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">&quot;&quot;</span> ) )
187
- 184: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
188
- 185: <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">&quot;Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'&quot;</span>
189
- 186: <span class="ruby-keyword kw">else</span>
190
- 187: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>
191
- 188: <span class="ruby-keyword kw">end</span>
130
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 130</span>
131
+ 130: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Route</span> <span class="ruby-operator">*</span><span class="ruby-identifier">u</span>
132
+ 131: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span> {
133
+ 132: <span class="ruby-identifier">meta_def</span>(<span class="ruby-identifier">:__urls__</span>){
134
+ 133: <span class="ruby-comment cmt"># &lt; Route '/hello/world/([^\/]*)/id(\d*)', '/hello/(.*)'</span>
135
+ 134: <span class="ruby-comment cmt"># # =&gt; [ {'/hello/world' =&gt; '([^\/]*)/id(\d*)', '/hello' =&gt; '(.*)'}, 2, &lt;Capcode::Klass&gt; ]</span>
136
+ 135: <span class="ruby-identifier">h</span> = {}
137
+ 136: <span class="ruby-identifier">max</span> = <span class="ruby-value">0</span>
138
+ 137: <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>
139
+ 138: <span class="ruby-identifier">m</span> = <span class="ruby-regexp re">/\/([^\/]*\(.*)/</span>.<span class="ruby-identifier">match</span>( <span class="ruby-identifier">_u</span> )
140
+ 139: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
141
+ 140: <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">&quot;Route `#{_u}' already defined with regexp `#{h[_u]}' !&quot;</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>)
142
+ 141: <span class="ruby-identifier">h</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-value str">''</span>
143
+ 142: <span class="ruby-keyword kw">else</span>
144
+ 143: <span class="ruby-identifier">_pre</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">pre_match</span>
145
+ 144: <span class="ruby-identifier">_pre</span> = <span class="ruby-value str">&quot;/&quot;</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>
146
+ 145: <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">&quot;Route `#{_pre}' already defined with regexp `#{h[_pre]}' !&quot;</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>)
147
+ 146: <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>]
148
+ 147: <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">&lt;</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>
149
+ 148: <span class="ruby-keyword kw">end</span>
150
+ 149: <span class="ruby-keyword kw">end</span>
151
+ 150: [<span class="ruby-identifier">h</span>, <span class="ruby-identifier">max</span>, <span class="ruby-keyword kw">self</span>]
152
+ 151: }
153
+ 152:
154
+ 153: <span class="ruby-comment cmt"># Hash containing all the request parameters (GET or POST)</span>
155
+ 154: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
156
+ 155: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
157
+ 156: <span class="ruby-keyword kw">end</span>
158
+ 157:
159
+ 158: <span class="ruby-comment cmt"># Hash containing all the environment variables</span>
160
+ 159: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
161
+ 160: <span class="ruby-ivar">@env</span>
162
+ 161: <span class="ruby-keyword kw">end</span>
163
+ 162:
164
+ 163: <span class="ruby-comment cmt"># Hash session</span>
165
+ 164: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
166
+ 165: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
167
+ 166: <span class="ruby-keyword kw">end</span>
168
+ 167:
169
+ 168: <span class="ruby-comment cmt"># Return the Rack::Request object</span>
170
+ 169: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
171
+ 170: <span class="ruby-ivar">@request</span>
172
+ 171: <span class="ruby-keyword kw">end</span>
173
+ 172:
174
+ 173: <span class="ruby-comment cmt"># Return the Rack::Response object</span>
175
+ 174: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
176
+ 175: <span class="ruby-ivar">@response</span>
177
+ 176: <span class="ruby-keyword kw">end</span>
178
+ 177:
179
+ 178: <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>
180
+ 179: <span class="ruby-ivar">@env</span> = <span class="ruby-identifier">e</span>
181
+ 180: <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>
182
+ 181: <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>)
183
+ 182:
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">&quot;REQUEST_METHOD&quot;</span>]
185
+ 184: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;GET&quot;</span>
186
+ 185: <span class="ruby-identifier">sc</span> = <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">script_name</span>
187
+ 186: <span class="ruby-identifier">sc</span> = <span class="ruby-value str">&quot;/&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sc</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
188
+ 187: <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">sc</span>] )
189
+ 188: <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>]
192
190
  189:
193
- 190: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">nargs</span>
194
- 191: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
195
- 192: <span class="ruby-keyword kw">end</span>
196
- 193:
197
- 194: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
198
- 195: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
199
- 196: <span class="ruby-identifier">post</span>
200
- 197: <span class="ruby-keyword kw">end</span>
201
- 198: <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>)
202
- 199: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
203
- 200: <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>
204
- 201: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
205
- 202: <span class="ruby-keyword kw">end</span>
206
- 203: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
207
- 204: <span class="ruby-keyword kw">else</span>
208
- 205: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
209
- 206: <span class="ruby-keyword kw">end</span>
210
- 207:
211
- 208: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
212
- 209: <span class="ruby-keyword kw">end</span>
213
- 210:
214
- 211: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
215
- 212: }
216
- 213: <span class="ruby-keyword kw">end</span>
191
+ 190: <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">&quot;&quot;</span> ) )
192
+ 191: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
193
+ 192: <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">&quot;Path info `#{@request.path_info}' does not match route regexp `#{regexp.source}'&quot;</span>
194
+ 193: <span class="ruby-keyword kw">else</span>
195
+ 194: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">captures</span>
196
+ 195: <span class="ruby-keyword kw">end</span>
197
+ 196:
198
+ 197: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">nargs</span>
199
+ 198: <span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
200
+ 199: <span class="ruby-keyword kw">end</span>
201
+ 200:
202
+ 201: <span class="ruby-identifier">get</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
203
+ 202: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;POST&quot;</span>
204
+ 203: <span class="ruby-identifier">post</span>
205
+ 204: <span class="ruby-keyword kw">end</span>
206
+ 205: <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>)
207
+ 206: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>]
208
+ 207: <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>
209
+ 208: <span class="ruby-ivar">@response</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
210
+ 209: <span class="ruby-keyword kw">end</span>
211
+ 210: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">r</span>[<span class="ruby-value">2</span>]
212
+ 211: <span class="ruby-keyword kw">else</span>
213
+ 212: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">r</span>
214
+ 213: <span class="ruby-keyword kw">end</span>
215
+ 214:
216
+ 215: <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">finish</span>
217
+ 216: <span class="ruby-keyword kw">end</span>
218
+ 217:
219
+ 218: <span class="ruby-identifier">include</span> <span class="ruby-constant">Capcode</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>
220
+ 219: }
221
+ 220: <span class="ruby-keyword kw">end</span>
217
222
  </pre>
218
223
  </div>
219
224
  </div>
@@ -228,10 +233,10 @@ Hash containing all the environment variables
228
233
  <p class="source-link">[ <a href="javascript:toggleSource('M000003_source')" id="l_M000003_source">show source</a> ]</p>
229
234
  <div id="M000003_source" class="dyn-source">
230
235
  <pre>
231
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 152</span>
232
- 152: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
233
- 153: <span class="ruby-ivar">@env</span>
234
- 154: <span class="ruby-keyword kw">end</span>
236
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 159</span>
237
+ 159: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">env</span>
238
+ 160: <span class="ruby-ivar">@env</span>
239
+ 161: <span class="ruby-keyword kw">end</span>
235
240
  </pre>
236
241
  </div>
237
242
  </div>
@@ -252,10 +257,10 @@ Rack or What you want Helper
252
257
  <p class="source-link">[ <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show source</a> ]</p>
253
258
  <div id="M000007_source" class="dyn-source">
254
259
  <pre>
255
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 220</span>
256
- 220: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">r</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
257
- 221: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
258
- 222: <span class="ruby-keyword kw">end</span>
260
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 227</span>
261
+ 227: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>( <span class="ruby-identifier">r</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span> )
262
+ 228: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">r</span>] = <span class="ruby-keyword kw">yield</span>
263
+ 229: <span class="ruby-keyword kw">end</span>
259
264
  </pre>
260
265
  </div>
261
266
  </div>
@@ -271,10 +276,10 @@ parameters (GET or POST)
271
276
  <p class="source-link">[ <a href="javascript:toggleSource('M000002_source')" id="l_M000002_source">show source</a> ]</p>
272
277
  <div id="M000002_source" class="dyn-source">
273
278
  <pre>
274
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 147</span>
275
- 147: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
276
- 148: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
277
- 149: <span class="ruby-keyword kw">end</span>
279
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 154</span>
280
+ 154: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
281
+ 155: <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">params</span>
282
+ 156: <span class="ruby-keyword kw">end</span>
278
283
  </pre>
279
284
  </div>
280
285
  </div>
@@ -289,10 +294,10 @@ Return the Rack::Request object
289
294
  <p class="source-link">[ <a href="javascript:toggleSource('M000005_source')" id="l_M000005_source">show source</a> ]</p>
290
295
  <div id="M000005_source" class="dyn-source">
291
296
  <pre>
292
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 162</span>
293
- 162: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
294
- 163: <span class="ruby-ivar">@request</span>
295
- 164: <span class="ruby-keyword kw">end</span>
297
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 169</span>
298
+ 169: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>
299
+ 170: <span class="ruby-ivar">@request</span>
300
+ 171: <span class="ruby-keyword kw">end</span>
296
301
  </pre>
297
302
  </div>
298
303
  </div>
@@ -307,10 +312,10 @@ Return the Rack::Response object
307
312
  <p class="source-link">[ <a href="javascript:toggleSource('M000006_source')" id="l_M000006_source">show source</a> ]</p>
308
313
  <div id="M000006_source" class="dyn-source">
309
314
  <pre>
310
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 167</span>
311
- 167: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
312
- 168: <span class="ruby-ivar">@response</span>
313
- 169: <span class="ruby-keyword kw">end</span>
315
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 174</span>
316
+ 174: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">response</span>
317
+ 175: <span class="ruby-ivar">@response</span>
318
+ 176: <span class="ruby-keyword kw">end</span>
314
319
  </pre>
315
320
  </div>
316
321
  </div>
@@ -339,6 +344,12 @@ Options :
339
344
  <li><tt>:<a href="Capcode.html#M000004">session</a></tt> = Session parameters.
340
345
  See Rack::Session for more informations
341
346
 
347
+ </li>
348
+ <li><tt>:pid</tt> = PID file (default: $0.pid)
349
+
350
+ </li>
351
+ <li><tt>:daemonize</tt> = Daemonize application (default: false)
352
+
342
353
  </li>
343
354
  </ul>
344
355
 
@@ -346,63 +357,91 @@ See Rack::Session for more informations
346
357
  <p class="source-link">[ <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show source</a> ]</p>
347
358
  <div id="M000008_source" class="dyn-source">
348
359
  <pre>
349
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 232</span>
350
- 232: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
351
- 233: <span class="ruby-identifier">conf</span> = {
352
- 234: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:port</span>]<span class="ruby-operator">||</span><span class="ruby-value">3000</span>,
353
- 235: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:host</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;localhost&quot;</span>,
354
- 236: <span class="ruby-identifier">:server</span> =<span class="ruby-operator">&gt;</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>,
355
- 237: <span class="ruby-identifier">:log</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:log</span>]<span class="ruby-operator">||</span><span class="ruby-identifier">$stdout</span>,
356
- 238: <span class="ruby-identifier">:session</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:session</span>]<span class="ruby-operator">||</span>{}
357
- 239: }
358
- 240:
359
- 241: <span class="ruby-comment cmt"># Check that mongrel exists </span>
360
- 242: <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">&quot;mongrel&quot;</span>
361
- 243: <span class="ruby-keyword kw">begin</span>
362
- 244: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
363
- 245: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;mongrel&quot;</span>
364
- 246: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
365
- 247: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
366
- 248: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;webrick&quot;</span>
367
- 249: <span class="ruby-keyword kw">end</span>
368
- 250: <span class="ruby-keyword kw">end</span>
369
- 251:
370
- 252: <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>
371
- 253: <span class="ruby-keyword kw">begin</span>
372
- 254: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.public_methods(true).include?( '__urls__' )&quot;</span>
373
- 255: <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">&quot;Capcode::#{k}.__urls__&quot;</span>
374
- 256: <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>
375
- 257: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
376
- 258: <span class="ruby-keyword kw">end</span>
377
- 259: <span class="ruby-keyword kw">end</span>
378
- 260: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
379
- 261: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
380
- 262: <span class="ruby-keyword kw">end</span>
381
- 263: <span class="ruby-keyword kw">end</span>
382
- 264:
383
- 265: <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>)
384
- 266: <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>] )
385
- 267: <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>)
386
- 268: <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>)
387
- 269: <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>)
388
- 270: <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>)
389
- 271: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
390
- 272: <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>]) )
391
- 273:
392
- 274:
393
- 275: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
394
- 276: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
395
- 277: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{conf[:host]}:#{conf[:port]}&quot;</span>
396
- 278: <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">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</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>
397
- 279: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
398
- 280: }
399
- 281: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
400
- 282: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{conf[:host]}:#{conf[:port]}&quot;</span>
401
- 283: <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">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</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>
402
- 284: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
403
- 285: }
404
- 286: <span class="ruby-keyword kw">end</span>
405
- 287: <span class="ruby-keyword kw">end</span>
360
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 241</span>
361
+ 241: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>( <span class="ruby-identifier">args</span> = {} )
362
+ 242: <span class="ruby-identifier">conf</span> = {
363
+ 243: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:port</span>]<span class="ruby-operator">||</span><span class="ruby-value">3000</span>,
364
+ 244: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:host</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;localhost&quot;</span>,
365
+ 245: <span class="ruby-identifier">:server</span> =<span class="ruby-operator">&gt;</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>,
366
+ 246: <span class="ruby-identifier">:log</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:log</span>]<span class="ruby-operator">||</span><span class="ruby-identifier">$stdout</span>,
367
+ 247: <span class="ruby-identifier">:session</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:session</span>]<span class="ruby-operator">||</span>{},
368
+ 248: <span class="ruby-identifier">:pid</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:pid</span>]<span class="ruby-operator">||</span><span class="ruby-node">&quot;#{$0}.pid&quot;</span>,
369
+ 249: <span class="ruby-identifier">:daemonize</span> =<span class="ruby-operator">&gt;</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>,
370
+ 250: <span class="ruby-identifier">:db_config</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:db_config</span>]<span class="ruby-operator">||</span><span class="ruby-value str">&quot;database.yml&quot;</span>
371
+ 251: }
372
+ 252:
373
+ 253: <span class="ruby-comment cmt"># Check that mongrel exists </span>
374
+ 254: <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">&quot;mongrel&quot;</span>
375
+ 255: <span class="ruby-keyword kw">begin</span>
376
+ 256: <span class="ruby-identifier">require</span> <span class="ruby-value str">'mongrel'</span>
377
+ 257: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;mongrel&quot;</span>
378
+ 258: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
379
+ 259: <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;!! could not load mongrel. Falling back to webrick.&quot;</span>
380
+ 260: <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>] = <span class="ruby-value str">&quot;webrick&quot;</span>
381
+ 261: <span class="ruby-keyword kw">end</span>
382
+ 262: <span class="ruby-keyword kw">end</span>
383
+ 263:
384
+ 264: <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>
385
+ 265: <span class="ruby-keyword kw">begin</span>
386
+ 266: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;Capcode::#{k}.public_methods(true).include?( '__urls__' )&quot;</span>
387
+ 267: <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">&quot;Capcode::#{k}.__urls__&quot;</span>
388
+ 268: <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>
389
+ 269: <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">&quot;Route `#{_u}' already define !&quot;</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>)
390
+ 270: <span class="ruby-ivar">@@__ROUTES</span>[<span class="ruby-identifier">_u</span>] = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>
391
+ 271: <span class="ruby-keyword kw">end</span>
392
+ 272: <span class="ruby-keyword kw">end</span>
393
+ 273: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
394
+ 274: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
395
+ 275: <span class="ruby-keyword kw">end</span>
396
+ 276: <span class="ruby-keyword kw">end</span>
397
+ 277:
398
+ 278: <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>)
399
+ 279: <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>] )
400
+ 280: <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>)
401
+ 281: <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>)
402
+ 282: <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>)
403
+ 283: <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>)
404
+ 284: <span class="ruby-comment cmt"># app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!</span>
405
+ 285: <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>]) )
406
+ 286:
407
+ 287: <span class="ruby-comment cmt"># From rackup !!!</span>
408
+ 288: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:daemonize</span>]
409
+ 289: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value str">&quot;1.9&quot;</span>
410
+ 290: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
411
+ 291: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
412
+ 292: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
413
+ 293: <span class="ruby-comment cmt"># Dir.chdir &quot;/&quot;</span>
414
+ 294: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
415
+ 295: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>
416
+ 296: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
417
+ 297: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">&quot;/dev/null&quot;</span>, <span class="ruby-value str">&quot;a&quot;</span>
418
+ 298: <span class="ruby-keyword kw">else</span>
419
+ 299: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">daemon</span>
420
+ 300: <span class="ruby-keyword kw">end</span>
421
+ 301:
422
+ 302: <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">&quot;#{Process.pid}&quot;</span>) }
423
+ 303: <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>]) }
424
+ 304: <span class="ruby-keyword kw">end</span>
425
+ 305:
426
+ 306: <span class="ruby-comment cmt"># Start database</span>
427
+ 307: <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">&quot;db_connect&quot;</span>
428
+ 308: <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>] )
429
+ 309: <span class="ruby-keyword kw">end</span>
430
+ 310:
431
+ 311: <span class="ruby-comment cmt"># Start server</span>
432
+ 312: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:server</span>]
433
+ 313: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;mongrel&quot;</span>
434
+ 314: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting Mongrel on #{conf[:host]}:#{conf[:port]}&quot;</span>
435
+ 315: <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">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:Host</span> =<span class="ruby-operator">&gt;</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>
436
+ 316: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">stop</span> }
437
+ 317: }
438
+ 318: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;webrick&quot;</span>
439
+ 319: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;** Starting WEBrick on #{conf[:host]}:#{conf[:port]}&quot;</span>
440
+ 320: <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">&gt;</span> <span class="ruby-identifier">conf</span>[<span class="ruby-identifier">:port</span>], <span class="ruby-identifier">:BindAddress</span> =<span class="ruby-operator">&gt;</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>
441
+ 321: <span class="ruby-identifier">trap</span> <span class="ruby-value str">&quot;SIGINT&quot;</span>, <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
442
+ 322: }
443
+ 323: <span class="ruby-keyword kw">end</span>
444
+ 324: <span class="ruby-keyword kw">end</span>
406
445
  </pre>
407
446
  </div>
408
447
  </div>
@@ -417,10 +456,10 @@ Hash <a href="Capcode.html#M000004">session</a>
417
456
  <p class="source-link">[ <a href="javascript:toggleSource('M000004_source')" id="l_M000004_source">show source</a> ]</p>
418
457
  <div id="M000004_source" class="dyn-source">
419
458
  <pre>
420
- <span class="ruby-comment cmt"># File lib/capcode.rb, line 157</span>
421
- 157: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
422
- 158: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
423
- 159: <span class="ruby-keyword kw">end</span>
459
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 164</span>
460
+ 164: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>
461
+ 165: <span class="ruby-ivar">@env</span>[<span class="ruby-value str">'rack.session'</span>]
462
+ 166: <span class="ruby-keyword kw">end</span>
424
463
  </pre>
425
464
  </div>
426
465
  </div>