instiki/vendor/plugins/rack/doc/classes/Rack/Builder.html

340 lines
14 KiB
HTML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Class: Rack::Builder</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
<script type="text/javascript">
// <![CDATA[
function popupCode( url ) {
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
}
function toggleCode( id ) {
if ( document.getElementById )
elem = document.getElementById( id );
else if ( document.all )
elem = eval( "document.all." + id );
else
return false;
elemStyle = elem.style;
if ( elemStyle.display != "block" ) {
elemStyle.display = "block"
} else {
elemStyle.display = "none"
}
return true;
}
// Make codeblocks hidden by default
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
// ]]>
</script>
</head>
<body>
<div id="classHeader">
<table class="header-table">
<tr class="top-aligned-row">
<td><strong>Class</strong></td>
<td class="class-name-in-header">Rack::Builder</td>
</tr>
<tr class="top-aligned-row">
<td><strong>In:</strong></td>
<td>
<a href="../../files/lib/rack/builder_rb.html">
lib/rack/builder.rb
</a>
<br />
</td>
</tr>
<tr class="top-aligned-row">
<td><strong>Parent:</strong></td>
<td>
Object
</td>
</tr>
</table>
</div>
<!-- banner header -->
<div id="bodyContent">
<div id="contextContent">
<div id="description">
<p>
<a href="Builder.html">Rack::Builder</a> implements a small DSL to
iteratively construct <a href="../Rack.html">Rack</a> applications.
</p>
<p>
Example:
</p>
<pre>
app = Rack::Builder.new {
use Rack::CommonLogger
use Rack::ShowExceptions
map &quot;/lobster&quot; do
use Rack::Lint
run Rack::Lobster.new
end
}
</pre>
<p>
Or
</p>
<pre>
app = Rack::Builder.app do
use Rack::CommonLogger
lambda { |env| [200, {'Content-Type' =&gt; 'text/plain'}, 'OK'] }
end
</pre>
<p>
<tt><a href="Builder.html#M000127">use</a></tt> adds a middleware to the
stack, <tt><a href="Builder.html#M000128">run</a></tt> dispatches to an
application. You can <a href="Builder.html#M000127">use</a> <tt><a
href="Builder.html#M000129">map</a></tt> to construct a <a
href="URLMap.html">Rack::URLMap</a> in a convenient way.
</p>
</div>
</div>
<div id="method-list">
<h3 class="section-bar">Methods</h3>
<div class="name-list">
<a href="#M000126">app</a>&nbsp;&nbsp;
<a href="#M000131">call</a>&nbsp;&nbsp;
<a href="#M000129">map</a>&nbsp;&nbsp;
<a href="#M000125">new</a>&nbsp;&nbsp;
<a href="#M000128">run</a>&nbsp;&nbsp;
<a href="#M000130">to_app</a>&nbsp;&nbsp;
<a href="#M000127">use</a>&nbsp;&nbsp;
</div>
</div>
</div>
<!-- if includes -->
<div id="section">
<!-- if method_list -->
<div id="methods">
<h3 class="section-bar">Public Class methods</h3>
<div id="method-M000126" class="method-detail">
<a name="M000126"></a>
<div class="method-heading">
<a href="#M000126" class="method-signature">
<span class="method-name">app</span><span class="method-args">(&amp;block)</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000126-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000126-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/builder.rb, line 32</span>
32: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">app</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
33: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>).<span class="ruby-identifier">to_app</span>
34: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000125" class="method-detail">
<a name="M000125"></a>
<div class="method-heading">
<a href="#M000125" class="method-signature">
<span class="method-name">new</span><span class="method-args">(&amp;block)</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000125-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000125-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/builder.rb, line 27</span>
27: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
28: <span class="ruby-ivar">@ins</span> = []
29: <span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
30: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<h3 class="section-bar">Public Instance methods</h3>
<div id="method-M000131" class="method-detail">
<a name="M000131"></a>
<div class="method-heading">
<a href="#M000131" class="method-signature">
<span class="method-name">call</span><span class="method-args">(env)</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000131-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000131-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/builder.rb, line 63</span>
63: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
64: <span class="ruby-identifier">to_app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
65: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000129" class="method-detail">
<a name="M000129"></a>
<div class="method-heading">
<a href="#M000129" class="method-signature">
<span class="method-name">map</span><span class="method-args">(path, &amp;block)</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000129-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000129-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/builder.rb, line 48</span>
48: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>(<span class="ruby-identifier">path</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
49: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@ins</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Hash</span>
50: <span class="ruby-ivar">@ins</span>.<span class="ruby-identifier">last</span>[<span class="ruby-identifier">path</span>] = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>).<span class="ruby-identifier">to_app</span>
51: <span class="ruby-keyword kw">else</span>
52: <span class="ruby-ivar">@ins</span> <span class="ruby-operator">&lt;&lt;</span> {}
53: <span class="ruby-identifier">map</span>(<span class="ruby-identifier">path</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
54: <span class="ruby-keyword kw">end</span>
55: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000128" class="method-detail">
<a name="M000128"></a>
<div class="method-heading">
<a href="#M000128" class="method-signature">
<span class="method-name">run</span><span class="method-args">(app)</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000128-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000128-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/builder.rb, line 44</span>
44: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>(<span class="ruby-identifier">app</span>)
45: <span class="ruby-ivar">@ins</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">app</span> <span class="ruby-comment cmt">#lambda { |nothing| app }</span>
46: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000130" class="method-detail">
<a name="M000130"></a>
<div class="method-heading">
<a href="#M000130" class="method-signature">
<span class="method-name">to_app</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000130-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000130-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/builder.rb, line 57</span>
57: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_app</span>
58: <span class="ruby-ivar">@ins</span>[<span class="ruby-value">-1</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">@ins</span>.<span class="ruby-identifier">last</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Hash</span> <span class="ruby-operator">===</span> <span class="ruby-ivar">@ins</span>.<span class="ruby-identifier">last</span>
59: <span class="ruby-identifier">inner_app</span> = <span class="ruby-ivar">@ins</span>.<span class="ruby-identifier">last</span>
60: <span class="ruby-ivar">@ins</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-identifier">inner_app</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span>, <span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">a</span>) }
61: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000127" class="method-detail">
<a name="M000127"></a>
<div class="method-heading">
<a href="#M000127" class="method-signature">
<span class="method-name">use</span><span class="method-args">(middleware, *args, &amp;block)</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000127-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000127-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/builder.rb, line 36</span>
36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use</span>(<span class="ruby-identifier">middleware</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
37: <span class="ruby-ivar">@ins</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
38: <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">app</span><span class="ruby-operator">|</span> <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) }
39: <span class="ruby-keyword kw">else</span>
40: <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">app</span><span class="ruby-operator">|</span> <span class="ruby-identifier">middleware</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>) }
41: <span class="ruby-keyword kw">end</span>
42: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="validator-badges">
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>
</body>
</html>