serverside 0.2.5 → 0.2.6
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/CHANGELOG +10 -0
- data/README +3 -3
- data/Rakefile +4 -4
- data/bin/serverside +4 -4
- data/doc/rdoc/classes/Daemon.html +4 -4
- data/doc/rdoc/classes/ServerSide.html +14 -74
- data/doc/rdoc/classes/ServerSide/Application.html +13 -13
- data/doc/rdoc/classes/ServerSide/{Connection.html → HTTP.html} +12 -18
- data/doc/rdoc/classes/ServerSide/HTTP/Connection.html +200 -0
- data/doc/rdoc/classes/ServerSide/{Connection → HTTP}/Const.html +6 -6
- data/doc/rdoc/classes/ServerSide/{Connection/Base.html → HTTP/Request.html} +213 -164
- data/doc/rdoc/classes/ServerSide/{Server.html → HTTP/Server.html} +22 -22
- data/doc/rdoc/classes/ServerSide/Router.html +496 -0
- data/doc/rdoc/classes/ServerSide/StaticFiles.html +31 -30
- data/doc/rdoc/classes/ServerSide/Template.html +12 -12
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGELOG.html +22 -4
- data/doc/rdoc/files/COPYING.html +1 -1
- data/doc/rdoc/files/README.html +4 -4
- data/doc/rdoc/files/lib/serverside/application_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/cluster_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/connection_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/core_ext_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/daemon_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/request_rb.html +101 -0
- data/doc/rdoc/files/lib/serverside/routing_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/server_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/static_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/template_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside_rb.html +1 -1
- data/doc/rdoc/fr_class_index.html +6 -5
- data/doc/rdoc/fr_file_index.html +1 -0
- data/doc/rdoc/fr_method_index.html +31 -31
- data/lib/serverside/application.rb +1 -1
- data/lib/serverside/connection.rb +12 -141
- data/lib/serverside/request.rb +150 -0
- data/lib/serverside/routing.rb +117 -126
- data/lib/serverside/server.rb +13 -12
- data/lib/serverside/static.rb +1 -1
- data/test/functional/primitive_static_server_test.rb +3 -3
- data/test/functional/routing_server.rb +1 -1
- data/test/functional/routing_server_test.rb +1 -1
- data/test/functional/static_profile.rb +1 -1
- data/test/functional/static_server_test.rb +2 -2
- data/test/unit/connection_test.rb +30 -224
- data/test/unit/request_test.rb +248 -0
- data/test/unit/routing_test.rb +4 -4
- data/test/unit/server_test.rb +10 -8
- data/test/unit/static_test.rb +1 -1
- metadata +61 -56
- data/doc/rdoc/classes/ServerSide/Connection/Router.html +0 -493
@@ -5,10 +5,10 @@
|
|
5
5
|
|
6
6
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
7
|
<head>
|
8
|
-
<title>Class: ServerSide::Server</title>
|
8
|
+
<title>Class: ServerSide::HTTP::Server</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
10
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href="
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
12
|
<script type="text/javascript">
|
13
13
|
// <![CDATA[
|
14
14
|
|
@@ -50,12 +50,12 @@
|
|
50
50
|
<table class="header-table">
|
51
51
|
<tr class="top-aligned-row">
|
52
52
|
<td><strong>Class</strong></td>
|
53
|
-
<td class="class-name-in-header">ServerSide::Server</td>
|
53
|
+
<td class="class-name-in-header">ServerSide::HTTP::Server</td>
|
54
54
|
</tr>
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
-
<a href="
|
58
|
+
<a href="../../../files/lib/serverside/server_rb.html">
|
59
59
|
lib/serverside/server.rb
|
60
60
|
</a>
|
61
61
|
<br />
|
@@ -65,7 +65,7 @@
|
|
65
65
|
<tr class="top-aligned-row">
|
66
66
|
<td><strong>Parent:</strong></td>
|
67
67
|
<td>
|
68
|
-
<a href="
|
68
|
+
<a href="../../Object.html">
|
69
69
|
Object
|
70
70
|
</a>
|
71
71
|
</td>
|
@@ -82,10 +82,11 @@
|
|
82
82
|
|
83
83
|
<div id="description">
|
84
84
|
<p>
|
85
|
-
The <a href="
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
The <a href="../../ServerSide.html">ServerSide</a> <a
|
86
|
+
href="../HTTP.html">HTTP</a> server is designed to be fast and simple. It
|
87
|
+
is also designed to support both <a href="../HTTP.html">HTTP</a> 1.1
|
88
|
+
persistent connections, and <a href="../HTTP.html">HTTP</a> streaming for
|
89
|
+
applications which use Comet techniques.
|
89
90
|
</p>
|
90
91
|
|
91
92
|
</div>
|
@@ -97,7 +98,7 @@ techniques.
|
|
97
98
|
<h3 class="section-bar">Methods</h3>
|
98
99
|
|
99
100
|
<div class="name-list">
|
100
|
-
<a href="#
|
101
|
+
<a href="#M000028">new</a>
|
101
102
|
</div>
|
102
103
|
</div>
|
103
104
|
|
@@ -119,12 +120,12 @@ techniques.
|
|
119
120
|
<div id="methods">
|
120
121
|
<h3 class="section-bar">Public Class methods</h3>
|
121
122
|
|
122
|
-
<div id="method-
|
123
|
-
<a name="
|
123
|
+
<div id="method-M000028" class="method-detail">
|
124
|
+
<a name="M000028"></a>
|
124
125
|
|
125
126
|
<div class="method-heading">
|
126
|
-
<a href="#
|
127
|
-
<span class="method-name">new</span><span class="method-args">(host, port,
|
127
|
+
<a href="#M000028" class="method-signature">
|
128
|
+
<span class="method-name">new</span><span class="method-args">(host, port, request_class)</span>
|
128
129
|
</a>
|
129
130
|
</div>
|
130
131
|
|
@@ -135,15 +136,14 @@ loop. When a new connection is accepted, a new instance of the supplied
|
|
135
136
|
connection class is instantiated and passed the connection for processing.
|
136
137
|
</p>
|
137
138
|
<p><a class="source-toggle" href="#"
|
138
|
-
onclick="toggleCode('
|
139
|
-
<div class="method-source-code" id="
|
139
|
+
onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
|
140
|
+
<div class="method-source-code" id="M000028-source">
|
140
141
|
<pre>
|
141
|
-
<span class="ruby-comment cmt"># File lib/serverside/server.rb, line
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
16: <span class="ruby-keyword kw">end</span>
|
142
|
+
<span class="ruby-comment cmt"># File lib/serverside/server.rb, line 13</span>
|
143
|
+
13: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">request_class</span>)
|
144
|
+
14: <span class="ruby-ivar">@server</span> = <span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>)
|
145
|
+
15: <span class="ruby-identifier">loop</span> {<span class="ruby-constant">Connection</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@server</span>.<span class="ruby-identifier">accept</span>, <span class="ruby-identifier">request_class</span>)}
|
146
|
+
16: <span class="ruby-keyword kw">end</span>
|
147
147
|
</pre>
|
148
148
|
</div>
|
149
149
|
</div>
|
@@ -0,0 +1,496 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: ServerSide::Router</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">ServerSide::Router</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/serverside/routing_rb.html">
|
59
|
+
lib/serverside/routing.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
<a href="HTTP/Request.html">
|
69
|
+
HTTP::Request
|
70
|
+
</a>
|
71
|
+
</td>
|
72
|
+
</tr>
|
73
|
+
</table>
|
74
|
+
</div>
|
75
|
+
<!-- banner header -->
|
76
|
+
|
77
|
+
<div id="bodyContent">
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<div id="contextContent">
|
82
|
+
|
83
|
+
<div id="description">
|
84
|
+
<p>
|
85
|
+
The <a href="Router.html">Router</a> class defines a kind of connection
|
86
|
+
that can route requests to different handlers based on rules that can be
|
87
|
+
specified either by lambdas or by hashes that contain variable names
|
88
|
+
corresponding to patterns.
|
89
|
+
</p>
|
90
|
+
<p>
|
91
|
+
The simplest form of a routing rule specifies a path pattern:
|
92
|
+
</p>
|
93
|
+
<pre>
|
94
|
+
ServerSide.route('/static') {serve_static('.'/@path)}
|
95
|
+
</pre>
|
96
|
+
<p>
|
97
|
+
But you can also check for other attributes of the request:
|
98
|
+
</p>
|
99
|
+
<pre>
|
100
|
+
ServerSide.route(:path => '/static', :host => '^:subdomain\.mydomain') {
|
101
|
+
serve_static(@parameters[:subdomain]/@path)
|
102
|
+
}
|
103
|
+
</pre>
|
104
|
+
<p>
|
105
|
+
It also possible to pass a lambda as a rule:
|
106
|
+
</p>
|
107
|
+
<pre>
|
108
|
+
ServerSide.route(lambda {@headers['Agent'] =~ /Moz/}) {serve_static('moz'/@path)}
|
109
|
+
</pre>
|
110
|
+
<p>
|
111
|
+
Routing rules are evaluated in backwards, so the rules should be ordered
|
112
|
+
from the general to the specific.
|
113
|
+
</p>
|
114
|
+
|
115
|
+
</div>
|
116
|
+
|
117
|
+
|
118
|
+
</div>
|
119
|
+
|
120
|
+
<div id="method-list">
|
121
|
+
<h3 class="section-bar">Methods</h3>
|
122
|
+
|
123
|
+
<div class="name-list">
|
124
|
+
<a href="#M000049">cache_constant</a>
|
125
|
+
<a href="#M000045">compile_rules</a>
|
126
|
+
<a href="#M000047">condition_part</a>
|
127
|
+
<a href="#M000052">default_handler</a>
|
128
|
+
<a href="#M000048">define_proc</a>
|
129
|
+
<a href="#M000043">has_routes?</a>
|
130
|
+
<a href="#M000044">route</a>
|
131
|
+
<a href="#M000050">route_default</a>
|
132
|
+
<a href="#M000046">rule_to_statement</a>
|
133
|
+
<a href="#M000051">unhandled</a>
|
134
|
+
</div>
|
135
|
+
</div>
|
136
|
+
|
137
|
+
</div>
|
138
|
+
|
139
|
+
|
140
|
+
<!-- if includes -->
|
141
|
+
|
142
|
+
<div id="section">
|
143
|
+
|
144
|
+
|
145
|
+
<div id="constants-list">
|
146
|
+
<h3 class="section-bar">Constants</h3>
|
147
|
+
|
148
|
+
<div class="name-list">
|
149
|
+
<table summary="Constants">
|
150
|
+
<tr class="top-aligned-row context-row">
|
151
|
+
<td class="context-item-name">ParamRegexp</td>
|
152
|
+
<td>=</td>
|
153
|
+
<td class="context-item-value">/(?::([a-z]+))/</td>
|
154
|
+
<td width="3em"> </td>
|
155
|
+
<td class="context-item-desc">
|
156
|
+
Pattern for finding parameters inside patterns. Parameters are parts of the
|
157
|
+
pattern, which the routing pre-processor turns into sub-regexp that are
|
158
|
+
used to extract parameter values from the pattern.
|
159
|
+
|
160
|
+
<p>
|
161
|
+
For example, matching ’/controller/show’ against
|
162
|
+
’/controller/:action’ will give us @parameters[:action] #=>
|
163
|
+
"show"
|
164
|
+
</p>
|
165
|
+
</td>
|
166
|
+
</tr>
|
167
|
+
</table>
|
168
|
+
</div>
|
169
|
+
</div>
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
<!-- if method_list -->
|
177
|
+
<div id="methods">
|
178
|
+
<h3 class="section-bar">Public Class methods</h3>
|
179
|
+
|
180
|
+
<div id="method-M000049" class="method-detail">
|
181
|
+
<a name="M000049"></a>
|
182
|
+
|
183
|
+
<div class="method-heading">
|
184
|
+
<a href="#M000049" class="method-signature">
|
185
|
+
<span class="method-name">cache_constant</span><span class="method-args">(value)</span>
|
186
|
+
</a>
|
187
|
+
</div>
|
188
|
+
|
189
|
+
<div class="method-description">
|
190
|
+
<p>
|
191
|
+
Converts a value into a local constant and freezes it. Returns the
|
192
|
+
constant’s tag name
|
193
|
+
</p>
|
194
|
+
<p><a class="source-toggle" href="#"
|
195
|
+
onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
|
196
|
+
<div class="method-source-code" id="M000049-source">
|
197
|
+
<pre>
|
198
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 112</span>
|
199
|
+
112: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cache_constant</span>(<span class="ruby-identifier">value</span>)
|
200
|
+
113: <span class="ruby-identifier">tag</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">const_tag</span>
|
201
|
+
114: <span class="ruby-identifier">class_eval</span> <span class="ruby-node">"#{tag} = #{value.inspect}.freeze"</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
|
202
|
+
115: <span class="ruby-identifier">tag</span>
|
203
|
+
116: <span class="ruby-keyword kw">end</span>
|
204
|
+
</pre>
|
205
|
+
</div>
|
206
|
+
</div>
|
207
|
+
</div>
|
208
|
+
|
209
|
+
<div id="method-M000045" class="method-detail">
|
210
|
+
<a name="M000045"></a>
|
211
|
+
|
212
|
+
<div class="method-heading">
|
213
|
+
<a href="#M000045" class="method-signature">
|
214
|
+
<span class="method-name">compile_rules</span><span class="method-args">()</span>
|
215
|
+
</a>
|
216
|
+
</div>
|
217
|
+
|
218
|
+
<div class="method-description">
|
219
|
+
<p>
|
220
|
+
Compiles all rules into a respond method that is invoked when a request is
|
221
|
+
received.
|
222
|
+
</p>
|
223
|
+
<p><a class="source-toggle" href="#"
|
224
|
+
onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
|
225
|
+
<div class="method-source-code" id="M000045-source">
|
226
|
+
<pre>
|
227
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 47</span>
|
228
|
+
47: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile_rules</span>
|
229
|
+
48: <span class="ruby-ivar">@@rules</span> <span class="ruby-operator">||=</span> []
|
230
|
+
49: <span class="ruby-identifier">code</span> = <span class="ruby-ivar">@@rules</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value str">'lambda {'</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">m</span>, <span class="ruby-identifier">r</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">rule_to_statement</span>(<span class="ruby-identifier">r</span>[<span class="ruby-value">0</span>], <span class="ruby-identifier">r</span>[<span class="ruby-value">1</span>])}
|
231
|
+
50: <span class="ruby-identifier">code</span> <span class="ruby-operator"><<</span> <span class="ruby-value str">'default_handler}'</span>
|
232
|
+
51: <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">:respond</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">eval</span>(<span class="ruby-identifier">code</span>))
|
233
|
+
52: <span class="ruby-keyword kw">end</span>
|
234
|
+
</pre>
|
235
|
+
</div>
|
236
|
+
</div>
|
237
|
+
</div>
|
238
|
+
|
239
|
+
<div id="method-M000047" class="method-detail">
|
240
|
+
<a name="M000047"></a>
|
241
|
+
|
242
|
+
<div class="method-heading">
|
243
|
+
<a href="#M000047" class="method-signature">
|
244
|
+
<span class="method-name">condition_part</span><span class="method-args">(key, value)</span>
|
245
|
+
</a>
|
246
|
+
</div>
|
247
|
+
|
248
|
+
<div class="method-description">
|
249
|
+
<p>
|
250
|
+
Returns the condition part for the key and value specified. The key is the
|
251
|
+
name of an instance variable and the value is a pattern to match against.
|
252
|
+
If the pattern contains parameters (for example, /controller/:action,) the
|
253
|
+
method creates a lambda for extracting the parameter values.
|
254
|
+
</p>
|
255
|
+
<p><a class="source-toggle" href="#"
|
256
|
+
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
257
|
+
<div class="method-source-code" id="M000047-source">
|
258
|
+
<pre>
|
259
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 84</span>
|
260
|
+
84: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">condition_part</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
|
261
|
+
85: <span class="ruby-identifier">p_parse</span>, <span class="ruby-identifier">p_count</span> = <span class="ruby-value str">''</span>, <span class="ruby-value">0</span>
|
262
|
+
86: <span class="ruby-keyword kw">while</span> (<span class="ruby-constant">String</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">value</span>) <span class="ruby-operator">&&</span> (<span class="ruby-identifier">value</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">ParamRegexp</span>)
|
263
|
+
87: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">dup</span>
|
264
|
+
88: <span class="ruby-identifier">p_name</span> = <span class="ruby-identifier">$1</span>
|
265
|
+
89: <span class="ruby-identifier">p_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
266
|
+
90: <span class="ruby-identifier">value</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-constant">ParamRegexp</span>, <span class="ruby-value str">'(.+)'</span>)
|
267
|
+
91: <span class="ruby-identifier">p_parse</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"@parameters[:#{p_name}] = $#{p_count}\n"</span>
|
268
|
+
92: <span class="ruby-keyword kw">end</span>
|
269
|
+
93: <span class="ruby-identifier">cond</span> = <span class="ruby-node">"(@#{key} =~ #{cache_constant(Regexp.new(value))})"</span>
|
270
|
+
94: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">p_count</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
271
|
+
95: <span class="ruby-identifier">cond</span>
|
272
|
+
96: <span class="ruby-keyword kw">else</span>
|
273
|
+
97: <span class="ruby-identifier">tag</span> = <span class="ruby-identifier">define_proc</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">eval</span>(
|
274
|
+
98: <span class="ruby-node">"lambda {if #{cond}\n#{p_parse}true\nelse\nfalse\nend}"</span>))
|
275
|
+
99: <span class="ruby-node">"(#{tag})"</span>
|
276
|
+
100: <span class="ruby-keyword kw">end</span>
|
277
|
+
101: <span class="ruby-keyword kw">end</span>
|
278
|
+
</pre>
|
279
|
+
</div>
|
280
|
+
</div>
|
281
|
+
</div>
|
282
|
+
|
283
|
+
<div id="method-M000048" class="method-detail">
|
284
|
+
<a name="M000048"></a>
|
285
|
+
|
286
|
+
<div class="method-heading">
|
287
|
+
<a href="#M000048" class="method-signature">
|
288
|
+
<span class="method-name">define_proc</span><span class="method-args">(&block)</span>
|
289
|
+
</a>
|
290
|
+
</div>
|
291
|
+
|
292
|
+
<div class="method-description">
|
293
|
+
<p>
|
294
|
+
Converts a proc into a method, returning the method’s name (as a
|
295
|
+
symbol)
|
296
|
+
</p>
|
297
|
+
<p><a class="source-toggle" href="#"
|
298
|
+
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
299
|
+
<div class="method-source-code" id="M000048-source">
|
300
|
+
<pre>
|
301
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 104</span>
|
302
|
+
104: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">define_proc</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
303
|
+
105: <span class="ruby-identifier">tag</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">proc_tag</span>
|
304
|
+
106: <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">instance_methods</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">tag</span>)
|
305
|
+
107: <span class="ruby-identifier">tag</span>.<span class="ruby-identifier">to_sym</span>
|
306
|
+
108: <span class="ruby-keyword kw">end</span>
|
307
|
+
</pre>
|
308
|
+
</div>
|
309
|
+
</div>
|
310
|
+
</div>
|
311
|
+
|
312
|
+
<div id="method-M000043" class="method-detail">
|
313
|
+
<a name="M000043"></a>
|
314
|
+
|
315
|
+
<div class="method-heading">
|
316
|
+
<a href="#M000043" class="method-signature">
|
317
|
+
<span class="method-name">has_routes?</span><span class="method-args">()</span>
|
318
|
+
</a>
|
319
|
+
</div>
|
320
|
+
|
321
|
+
<div class="method-description">
|
322
|
+
<p>
|
323
|
+
Returns true if routes were defined.
|
324
|
+
</p>
|
325
|
+
<p><a class="source-toggle" href="#"
|
326
|
+
onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
|
327
|
+
<div class="method-source-code" id="M000043-source">
|
328
|
+
<pre>
|
329
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 26</span>
|
330
|
+
26: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">has_routes?</span>
|
331
|
+
27: <span class="ruby-ivar">@@rules</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@@rules</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">false</span>
|
332
|
+
28: <span class="ruby-keyword kw">end</span>
|
333
|
+
</pre>
|
334
|
+
</div>
|
335
|
+
</div>
|
336
|
+
</div>
|
337
|
+
|
338
|
+
<div id="method-M000044" class="method-detail">
|
339
|
+
<a name="M000044"></a>
|
340
|
+
|
341
|
+
<div class="method-heading">
|
342
|
+
<a href="#M000044" class="method-signature">
|
343
|
+
<span class="method-name">route</span><span class="method-args">(rule, &block)</span>
|
344
|
+
</a>
|
345
|
+
</div>
|
346
|
+
|
347
|
+
<div class="method-description">
|
348
|
+
<p>
|
349
|
+
Adds a routing rule. The normalized rule is a hash containing keys (acting
|
350
|
+
as instance variable names) with patterns as values. If the rule is not a
|
351
|
+
hash, it is normalized into a pattern checked against the request path.
|
352
|
+
Pattern values can also be arrays, any member of which is checked as a
|
353
|
+
pattern. The rule can also be a <a href="../Proc.html">Proc</a> or lambda
|
354
|
+
which is run with the connection object’s binding. A contrived
|
355
|
+
example:
|
356
|
+
</p>
|
357
|
+
<pre>
|
358
|
+
ServerSide.route(lambda{path = 'mypage'}) {serve_static('mypage.html')}
|
359
|
+
</pre>
|
360
|
+
<p><a class="source-toggle" href="#"
|
361
|
+
onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
|
362
|
+
<div class="method-source-code" id="M000044-source">
|
363
|
+
<pre>
|
364
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 38</span>
|
365
|
+
38: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">route</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
366
|
+
39: <span class="ruby-ivar">@@rules</span> <span class="ruby-operator">||=</span> []
|
367
|
+
40: <span class="ruby-identifier">rule</span> = {<span class="ruby-identifier">:path</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">rule</span>} <span class="ruby-keyword kw">unless</span> (<span class="ruby-constant">Hash</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">rule</span>) <span class="ruby-operator">||</span> (<span class="ruby-constant">Proc</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">rule</span>)
|
368
|
+
41: <span class="ruby-ivar">@@rules</span>.<span class="ruby-identifier">unshift</span> [<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">block</span>]
|
369
|
+
42: <span class="ruby-identifier">compile_rules</span>
|
370
|
+
43: <span class="ruby-keyword kw">end</span>
|
371
|
+
</pre>
|
372
|
+
</div>
|
373
|
+
</div>
|
374
|
+
</div>
|
375
|
+
|
376
|
+
<div id="method-M000050" class="method-detail">
|
377
|
+
<a name="M000050"></a>
|
378
|
+
|
379
|
+
<div class="method-heading">
|
380
|
+
<a href="#M000050" class="method-signature">
|
381
|
+
<span class="method-name">route_default</span><span class="method-args">(&block)</span>
|
382
|
+
</a>
|
383
|
+
</div>
|
384
|
+
|
385
|
+
<div class="method-description">
|
386
|
+
<p>
|
387
|
+
Sets the default handler for incoming requests.
|
388
|
+
</p>
|
389
|
+
<p><a class="source-toggle" href="#"
|
390
|
+
onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
|
391
|
+
<div class="method-source-code" id="M000050-source">
|
392
|
+
<pre>
|
393
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 119</span>
|
394
|
+
119: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">route_default</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
395
|
+
120: <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">:default_handler</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
396
|
+
121: <span class="ruby-identifier">compile_rules</span>
|
397
|
+
122: <span class="ruby-keyword kw">end</span>
|
398
|
+
</pre>
|
399
|
+
</div>
|
400
|
+
</div>
|
401
|
+
</div>
|
402
|
+
|
403
|
+
<div id="method-M000046" class="method-detail">
|
404
|
+
<a name="M000046"></a>
|
405
|
+
|
406
|
+
<div class="method-heading">
|
407
|
+
<a href="#M000046" class="method-signature">
|
408
|
+
<span class="method-name">rule_to_statement</span><span class="method-args">(rule, block)</span>
|
409
|
+
</a>
|
410
|
+
</div>
|
411
|
+
|
412
|
+
<div class="method-description">
|
413
|
+
<p>
|
414
|
+
Converts a rule into an if statement. All keys in the rule are matched
|
415
|
+
against their respective values.
|
416
|
+
</p>
|
417
|
+
<p><a class="source-toggle" href="#"
|
418
|
+
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
419
|
+
<div class="method-source-code" id="M000046-source">
|
420
|
+
<pre>
|
421
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 56</span>
|
422
|
+
56: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">rule_to_statement</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">block</span>)
|
423
|
+
57: <span class="ruby-identifier">proc_tag</span> = <span class="ruby-identifier">define_proc</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
424
|
+
58: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Proc</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">rule</span>
|
425
|
+
59: <span class="ruby-identifier">cond</span> = <span class="ruby-identifier">define_proc</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">rule</span>).<span class="ruby-identifier">to_s</span>
|
426
|
+
60: <span class="ruby-keyword kw">else</span>
|
427
|
+
61: <span class="ruby-identifier">cond</span> = <span class="ruby-identifier">rule</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">kv</span><span class="ruby-operator">|</span>
|
428
|
+
62: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Array</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">kv</span>[<span class="ruby-value">1</span>]
|
429
|
+
63: <span class="ruby-value str">'('</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">kv</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">condition_part</span>(<span class="ruby-identifier">kv</span>[<span class="ruby-value">0</span>], <span class="ruby-identifier">v</span>)}.<span class="ruby-identifier">join</span>(<span class="ruby-value str">'||'</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">')'</span>
|
430
|
+
64: <span class="ruby-keyword kw">else</span>
|
431
|
+
65: <span class="ruby-identifier">condition_part</span>(<span class="ruby-identifier">kv</span>[<span class="ruby-value">0</span>], <span class="ruby-identifier">kv</span>[<span class="ruby-value">1</span>])
|
432
|
+
66: <span class="ruby-keyword kw">end</span>
|
433
|
+
67: }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">'&&'</span>)
|
434
|
+
68: <span class="ruby-keyword kw">end</span>
|
435
|
+
69: <span class="ruby-node">"return #{proc_tag} if #{cond}\n"</span>
|
436
|
+
70: <span class="ruby-keyword kw">end</span>
|
437
|
+
</pre>
|
438
|
+
</div>
|
439
|
+
</div>
|
440
|
+
</div>
|
441
|
+
|
442
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
443
|
+
|
444
|
+
<div id="method-M000052" class="method-detail">
|
445
|
+
<a name="M000052"></a>
|
446
|
+
|
447
|
+
<div class="method-heading">
|
448
|
+
<span class="method-name">default_handler</span><span class="method-args">()</span>
|
449
|
+
</div>
|
450
|
+
|
451
|
+
<div class="method-description">
|
452
|
+
<p>
|
453
|
+
Alias for <a href="Router.html#M000051">unhandled</a>
|
454
|
+
</p>
|
455
|
+
</div>
|
456
|
+
</div>
|
457
|
+
|
458
|
+
<div id="method-M000051" class="method-detail">
|
459
|
+
<a name="M000051"></a>
|
460
|
+
|
461
|
+
<div class="method-heading">
|
462
|
+
<a href="#M000051" class="method-signature">
|
463
|
+
<span class="method-name">unhandled</span><span class="method-args">()</span>
|
464
|
+
</a>
|
465
|
+
</div>
|
466
|
+
|
467
|
+
<div class="method-description">
|
468
|
+
<p>
|
469
|
+
Generic responder for unhandled requests.
|
470
|
+
</p>
|
471
|
+
<p><a class="source-toggle" href="#"
|
472
|
+
onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
|
473
|
+
<div class="method-source-code" id="M000051-source">
|
474
|
+
<pre>
|
475
|
+
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 125</span>
|
476
|
+
125: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unhandled</span>
|
477
|
+
126: <span class="ruby-identifier">send_response</span>(<span class="ruby-value">403</span>, <span class="ruby-value str">'text'</span>, <span class="ruby-value str">'No handler found.'</span>)
|
478
|
+
127: <span class="ruby-keyword kw">end</span>
|
479
|
+
</pre>
|
480
|
+
</div>
|
481
|
+
</div>
|
482
|
+
</div>
|
483
|
+
|
484
|
+
|
485
|
+
</div>
|
486
|
+
|
487
|
+
|
488
|
+
</div>
|
489
|
+
|
490
|
+
|
491
|
+
<div id="validator-badges">
|
492
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
493
|
+
</div>
|
494
|
+
|
495
|
+
</body>
|
496
|
+
</html>
|