ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/ruby19/lib64/ruby/gems/1.9.1/doc/rack-1.6.4/rdoc/Rack/
Upload File :
Current File : //proc/thread-self/root/opt/alt/ruby19/lib64/ruby/gems/1.9.1/doc/rack-1.6.4/rdoc/Rack/Builder.html

<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=US-ASCII" http-equiv="Content-Type" />

  <title>Class: Rack::Builder</title>

  <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

  <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>

</head>
<body id="top" class="class">

  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="file-metadata">
      <div id="file-list-section" class="section">
        <h3 class="section-header">In Files</h3>
        <div class="section-body">
          <ul>
          
            <li><a href="../lib/rack/builder_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/rack/builder.rb">lib/rack/builder.rb</a></li>
          
          </ul>
        </div>
      </div>

      
    </div>

    <div id="class-metadata">
      
      <!-- Parent Class -->
      <div id="parent-class-section" class="section">
        <h3 class="section-header">Parent</h3>
        
        <p class="link"><a href="../Object.html">Object</a></p>
        
      </div>
      

      

      

      
      <!-- Method Quickref -->
      <div id="method-list-section" class="section">
        <h3 class="section-header">Methods</h3>
        <ul class="link-list">
          
          <li><a href="#method-c-app">::app</a></li>
          
          <li><a href="#method-c-new">::new</a></li>
          
          <li><a href="#method-c-new_from_string">::new_from_string</a></li>
          
          <li><a href="#method-c-parse_file">::parse_file</a></li>
          
          <li><a href="#method-i-call">#call</a></li>
          
          <li><a href="#method-i-map">#map</a></li>
          
          <li><a href="#method-i-run">#run</a></li>
          
          <li><a href="#method-i-to_app">#to_app</a></li>
          
          <li><a href="#method-i-use">#use</a></li>
          
          <li><a href="#method-i-warmup">#warmup</a></li>
          
        </ul>
      </div>
      

      
    </div>

    <div id="project-metadata">
      
      
      <div id="fileindex-section" class="section project-section">
        <h3 class="section-header">Files</h3>
        <ul>
        
          <li class="file"><a href="../KNOWN-ISSUES.html">KNOWN-ISSUES</a></li>
        
        </ul>
      </div>
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class/Module Index
          <span class="search-toggle"><img src="../images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="../Rack.html">Rack</a></li>
        
          <li><a href="../Rack/Auth.html">Rack::Auth</a></li>
        
          <li><a href="../Rack/Auth/AbstractHandler.html">Rack::Auth::AbstractHandler</a></li>
        
          <li><a href="../Rack/Auth/AbstractRequest.html">Rack::Auth::AbstractRequest</a></li>
        
          <li><a href="../Rack/Auth/Basic.html">Rack::Auth::Basic</a></li>
        
          <li><a href="../Rack/Auth/Basic/Request.html">Rack::Auth::Basic::Request</a></li>
        
          <li><a href="../Rack/Auth/Digest.html">Rack::Auth::Digest</a></li>
        
          <li><a href="../Rack/Auth/Digest/MD5.html">Rack::Auth::Digest::MD5</a></li>
        
          <li><a href="../Rack/Auth/Digest/Nonce.html">Rack::Auth::Digest::Nonce</a></li>
        
          <li><a href="../Rack/Auth/Digest/Params.html">Rack::Auth::Digest::Params</a></li>
        
          <li><a href="../Rack/Auth/Digest/Request.html">Rack::Auth::Digest::Request</a></li>
        
          <li><a href="../Rack/BodyProxy.html">Rack::BodyProxy</a></li>
        
          <li><a href="../Rack/Builder.html">Rack::Builder</a></li>
        
          <li><a href="../Rack/Cascade.html">Rack::Cascade</a></li>
        
          <li><a href="../Rack/Chunked.html">Rack::Chunked</a></li>
        
          <li><a href="../Rack/Chunked/Body.html">Rack::Chunked::Body</a></li>
        
          <li><a href="../Rack/CommonLogger.html">Rack::CommonLogger</a></li>
        
          <li><a href="../Rack/ConditionalGet.html">Rack::ConditionalGet</a></li>
        
          <li><a href="../Rack/Config.html">Rack::Config</a></li>
        
          <li><a href="../Rack/ContentLength.html">Rack::ContentLength</a></li>
        
          <li><a href="../Rack/ContentType.html">Rack::ContentType</a></li>
        
          <li><a href="../Rack/Deflater.html">Rack::Deflater</a></li>
        
          <li><a href="../Rack/Deflater/DeflateStream.html">Rack::Deflater::DeflateStream</a></li>
        
          <li><a href="../Rack/Deflater/GzipStream.html">Rack::Deflater::GzipStream</a></li>
        
          <li><a href="../Rack/Directory.html">Rack::Directory</a></li>
        
          <li><a href="../Rack/ETag.html">Rack::ETag</a></li>
        
          <li><a href="../Rack/File.html">Rack::File</a></li>
        
          <li><a href="../Rack/ForwardRequest.html">Rack::ForwardRequest</a></li>
        
          <li><a href="../Rack/Handler.html">Rack::Handler</a></li>
        
          <li><a href="../Rack/Handler/CGI.html">Rack::Handler::CGI</a></li>
        
          <li><a href="../Rack/Handler/EventedMongrel.html">Rack::Handler::EventedMongrel</a></li>
        
          <li><a href="../Rack/Handler/FastCGI.html">Rack::Handler::FastCGI</a></li>
        
          <li><a href="../Rack/Handler/LSWS.html">Rack::Handler::LSWS</a></li>
        
          <li><a href="../Rack/Handler/Mongrel.html">Rack::Handler::Mongrel</a></li>
        
          <li><a href="../Rack/Handler/SCGI.html">Rack::Handler::SCGI</a></li>
        
          <li><a href="../Rack/Handler/SwiftipliedMongrel.html">Rack::Handler::SwiftipliedMongrel</a></li>
        
          <li><a href="../Rack/Handler/Thin.html">Rack::Handler::Thin</a></li>
        
          <li><a href="../Rack/Handler/WEBrick.html">Rack::Handler::WEBrick</a></li>
        
          <li><a href="../Rack/Head.html">Rack::Head</a></li>
        
          <li><a href="../Rack/Lint.html">Rack::Lint</a></li>
        
          <li><a href="../Rack/Lobster.html">Rack::Lobster</a></li>
        
          <li><a href="../Rack/Lock.html">Rack::Lock</a></li>
        
          <li><a href="../Rack/Logger.html">Rack::Logger</a></li>
        
          <li><a href="../Rack/MethodOverride.html">Rack::MethodOverride</a></li>
        
          <li><a href="../Rack/Mime.html">Rack::Mime</a></li>
        
          <li><a href="../Rack/MockRequest.html">Rack::MockRequest</a></li>
        
          <li><a href="../Rack/MockRequest/FatalWarner.html">Rack::MockRequest::FatalWarner</a></li>
        
          <li><a href="../Rack/MockRequest/FatalWarning.html">Rack::MockRequest::FatalWarning</a></li>
        
          <li><a href="../Rack/MockResponse.html">Rack::MockResponse</a></li>
        
          <li><a href="../Rack/Multipart.html">Rack::Multipart</a></li>
        
          <li><a href="../Rack/Multipart/Generator.html">Rack::Multipart::Generator</a></li>
        
          <li><a href="../Rack/Multipart/MultipartPartLimitError.html">Rack::Multipart::MultipartPartLimitError</a></li>
        
          <li><a href="../Rack/Multipart/Parser.html">Rack::Multipart::Parser</a></li>
        
          <li><a href="../Rack/Multipart/UploadedFile.html">Rack::Multipart::UploadedFile</a></li>
        
          <li><a href="../Rack/NullLogger.html">Rack::NullLogger</a></li>
        
          <li><a href="../Rack/Recursive.html">Rack::Recursive</a></li>
        
          <li><a href="../Rack/Reloader.html">Rack::Reloader</a></li>
        
          <li><a href="../Rack/Reloader/Stat.html">Rack::Reloader::Stat</a></li>
        
          <li><a href="../Rack/Request.html">Rack::Request</a></li>
        
          <li><a href="../Rack/Response.html">Rack::Response</a></li>
        
          <li><a href="../Rack/Response/Helpers.html">Rack::Response::Helpers</a></li>
        
          <li><a href="../Rack/RewindableInput.html">Rack::RewindableInput</a></li>
        
          <li><a href="../Rack/RewindableInput/Tempfile.html">Rack::RewindableInput::Tempfile</a></li>
        
          <li><a href="../Rack/Runtime.html">Rack::Runtime</a></li>
        
          <li><a href="../Rack/Sendfile.html">Rack::Sendfile</a></li>
        
          <li><a href="../Rack/Server.html">Rack::Server</a></li>
        
          <li><a href="../Rack/Server/Options.html">Rack::Server::Options</a></li>
        
          <li><a href="../Rack/Session.html">Rack::Session</a></li>
        
          <li><a href="../Rack/Session/Abstract.html">Rack::Session::Abstract</a></li>
        
          <li><a href="../Rack/Session/Abstract/ID.html">Rack::Session::Abstract::ID</a></li>
        
          <li><a href="../Rack/Session/Abstract/SessionHash.html">Rack::Session::Abstract::SessionHash</a></li>
        
          <li><a href="../Rack/Session/Cookie.html">Rack::Session::Cookie</a></li>
        
          <li><a href="../Rack/Session/Cookie/Base64.html">Rack::Session::Cookie::Base64</a></li>
        
          <li><a href="../Rack/Session/Cookie/Base64/JSON.html">Rack::Session::Cookie::Base64::JSON</a></li>
        
          <li><a href="../Rack/Session/Cookie/Base64/Marshal.html">Rack::Session::Cookie::Base64::Marshal</a></li>
        
          <li><a href="../Rack/Session/Cookie/Base64/ZipJSON.html">Rack::Session::Cookie::Base64::ZipJSON</a></li>
        
          <li><a href="../Rack/Session/Cookie/Identity.html">Rack::Session::Cookie::Identity</a></li>
        
          <li><a href="../Rack/Session/Memcache.html">Rack::Session::Memcache</a></li>
        
          <li><a href="../Rack/Session/Pool.html">Rack::Session::Pool</a></li>
        
          <li><a href="../Rack/ShowExceptions.html">Rack::ShowExceptions</a></li>
        
          <li><a href="../Rack/ShowStatus.html">Rack::ShowStatus</a></li>
        
          <li><a href="../Rack/Static.html">Rack::Static</a></li>
        
          <li><a href="../Rack/TempfileReaper.html">Rack::TempfileReaper</a></li>
        
          <li><a href="../Rack/URLMap.html">Rack::URLMap</a></li>
        
          <li><a href="../Rack/Utils.html">Rack::Utils</a></li>
        
          <li><a href="../Rack/Utils/Context.html">Rack::Utils::Context</a></li>
        
          <li><a href="../Rack/Utils/HeaderHash.html">Rack::Utils::HeaderHash</a></li>
        
          <li><a href="../Rack/Utils/InvalidParameterError.html">Rack::Utils::InvalidParameterError</a></li>
        
          <li><a href="../Rack/Utils/KeySpaceConstrainedParams.html">Rack::Utils::KeySpaceConstrainedParams</a></li>
        
          <li><a href="../Rack/Multipart.html">Rack::Utils::Multipart</a></li>
        
          <li><a href="../Rack/Utils/OkJson.html">Rack::Utils::OkJson</a></li>
        
          <li><a href="../Rack/Utils/OkJson/Error.html">Rack::Utils::OkJson::Error</a></li>
        
          <li><a href="../Rack/Utils/OkJson/Utf8Error.html">Rack::Utils::OkJson::Utf8Error</a></li>
        
          <li><a href="../Rack/Utils/ParameterTypeError.html">Rack::Utils::ParameterTypeError</a></li>
        
          <li><a href="../FCGI.html">FCGI</a></li>
        
          <li><a href="../FCGI/Stream.html">FCGI::Stream</a></li>
        
          <li><a href="../WEBrick.html">WEBrick</a></li>
        
          <li><a href="../WEBrick/HTTPResponse.html">WEBrick::HTTPResponse</a></li>
        
          <li><a href="../Object.html">Object</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    <h1 class="class">Rack::Builder</h1>

    <div id="description" class="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>require 'rack/lobster'
app = Rack::Builder.new do
  use Rack::CommonLogger
  use Rack::ShowExceptions
  map &quot;/lobster&quot; do
    use Rack::Lint
    run Rack::Lobster.new
  end
end

run app</pre>

<p>Or</p>

<pre>app = Rack::Builder.app do
  use Rack::CommonLogger
  run lambda { |env| [200, {'Content-Type' =&gt; 'text/plain'}, ['OK']] }
end

run app</pre>

<p><tt>use</tt> adds middleware to the stack, <tt>run</tt> dispatches to an
application. You can use <tt>map</tt> to construct a <a
href="URLMap.html">Rack::URLMap</a> in a convenient way.</p>

    </div><!-- description -->

    
    
    
    <div id="5Buntitled-5D" class="documentation-section">
      

      

      

      

      <!-- Methods -->
      
      <div id="public-class-method-details" class="method-section section">
        <h3 class="section-header">Public Class Methods</h3>

      
        <div id="app-method" class="method-detail ">
          <a name="method-c-app"></a>

          
          <div class="method-heading">
            <span class="method-name">app</span><span
              class="method-args">(default_app = nil, &block)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="app-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 58</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">app</span>(<span class="ruby-identifier">default_app</span> = <span class="ruby-keyword">nil</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">default_app</span>, &amp;<span class="ruby-identifier">block</span>).<span class="ruby-identifier">to_app</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- app-source -->
            
          </div>

          

          
        </div><!-- app-method -->

      
        <div id="new-method" class="method-detail ">
          <a name="method-c-new"></a>

          
          <div class="method-heading">
            <span class="method-name">new</span><span
              class="method-args">(default_app = nil,&block)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="new-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 53</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">default_app</span> = <span class="ruby-keyword">nil</span>,&amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@use</span>, <span class="ruby-ivar">@map</span>, <span class="ruby-ivar">@run</span>, <span class="ruby-ivar">@warmup</span> = [], <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">default_app</span>, <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">instance_eval</span>(&amp;<span class="ruby-identifier">block</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- new-source -->
            
          </div>

          

          
        </div><!-- new-method -->

      
        <div id="new_from_string-method" class="method-detail ">
          <a name="method-c-new_from_string"></a>

          
          <div class="method-heading">
            <span class="method-name">new_from_string</span><span
              class="method-args">(builder_script, file="(rackup)")</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="new_from_string-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new_from_string</span>(<span class="ruby-identifier">builder_script</span>, <span class="ruby-identifier">file</span>=<span class="ruby-string">&quot;(rackup)&quot;</span>)
  <span class="ruby-identifier">eval</span> <span class="ruby-string">&quot;Rack::Builder.new {\n&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">builder_script</span> <span class="ruby-operator">+</span> <span class="ruby-string">&quot;\n}.to_app&quot;</span>,
    <span class="ruby-constant">TOPLEVEL_BINDING</span>, <span class="ruby-identifier">file</span>, <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- new_from_string-source -->
            
          </div>

          

          
        </div><!-- new_from_string-method -->

      
        <div id="parse_file-method" class="method-detail ">
          <a name="method-c-parse_file"></a>

          
          <div class="method-heading">
            <span class="method-name">parse_file</span><span
              class="method-args">(config, opts = Server::Options.new)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="parse_file-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 32</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">parse_file</span>(<span class="ruby-identifier">config</span>, <span class="ruby-identifier">opts</span> = <span class="ruby-constant">Server</span><span class="ruby-operator">::</span><span class="ruby-constant">Options</span>.<span class="ruby-identifier">new</span>)
  <span class="ruby-identifier">options</span> = {}
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">config</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\.ru$/</span>
    <span class="ruby-identifier">cfgfile</span> = <span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">config</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">cfgfile</span>[<span class="ruby-node">/^#\\(.*)/</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">opts</span>
      <span class="ruby-identifier">options</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-node">$1</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">/\s+/</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">cfgfile</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">/^__END__\n.*\Z/</span>, <span class="ruby-string">''</span>)
    <span class="ruby-identifier">app</span> = <span class="ruby-identifier">new_from_string</span> <span class="ruby-identifier">cfgfile</span>, <span class="ruby-identifier">config</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">require</span> <span class="ruby-identifier">config</span>
    <span class="ruby-identifier">app</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">config</span>, <span class="ruby-string">'.rb'</span>).<span class="ruby-identifier">capitalize</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">app</span>, <span class="ruby-identifier">options</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- parse_file-source -->
            
          </div>

          

          
        </div><!-- parse_file-method -->

      
      </div><!-- public-class-method-details -->
    
      <div id="public-instance-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>

      
        <div id="call-method" class="method-detail ">
          <a name="method-i-call"></a>

          
          <div class="method-heading">
            <span class="method-name">call</span><span
              class="method-args">(env)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="call-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 152</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
  <span class="ruby-identifier">to_app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
<span class="ruby-keyword">end</span></pre>
            </div><!-- call-source -->
            
          </div>

          

          
        </div><!-- call-method -->

      
        <div id="map-method" class="method-detail ">
          <a name="method-i-map"></a>

          
          <div class="method-heading">
            <span class="method-name">map</span><span
              class="method-args">(path, &block)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Creates a route within the application.</p>

<pre>Rack::Builder.app do
  map '/' do
    run Heartbeat
  end
end</pre>

<p>The <tt>use</tt> method can also be used here to specify middleware to run
under a specific path:</p>

<pre>Rack::Builder.app do
  map '/' do
    use Middleware
    run Heartbeat
  end
end</pre>

<p>This example includes a piece of middleware which will run before requests
hit <tt>Heartbeat</tt>.</p>
            

            
            <div class="method-source-code" id="map-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 139</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">map</span>(<span class="ruby-identifier">path</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@map</span> <span class="ruby-operator">||=</span> {}
  <span class="ruby-ivar">@map</span>[<span class="ruby-identifier">path</span>] = <span class="ruby-identifier">block</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- map-source -->
            
          </div>

          

          
        </div><!-- map-method -->

      
        <div id="run-method" class="method-detail ">
          <a name="method-i-run"></a>

          
          <div class="method-heading">
            <span class="method-name">run</span><span
              class="method-args">(app)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Takes an argument that is an object that responds to <a
href="Builder.html#method-i-call">call</a> and returns a <a
href="../Rack.html">Rack</a> response. The simplest form of this is a
lambda object:</p>

<pre>run lambda { |env| [200, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;OK&quot;]] }</pre>

<p>However this could also be a class:</p>

<pre>class Heartbeat
  def self.call(env)
   [200, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;OK&quot;]]
 end
end

run Heartbeat</pre>
            

            
            <div class="method-source-code" id="run-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 103</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">run</span>(<span class="ruby-identifier">app</span>)
  <span class="ruby-ivar">@run</span> = <span class="ruby-identifier">app</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- run-source -->
            
          </div>

          

          
        </div><!-- run-method -->

      
        <div id="to_app-method" class="method-detail ">
          <a name="method-i-to_app"></a>

          
          <div class="method-heading">
            <span class="method-name">to_app</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="to_app-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 144</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">to_app</span>
  <span class="ruby-identifier">app</span> = <span class="ruby-ivar">@map</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">generate_map</span>(<span class="ruby-ivar">@run</span>, <span class="ruby-ivar">@map</span>) <span class="ruby-operator">:</span> <span class="ruby-ivar">@run</span>
  <span class="ruby-identifier">fail</span> <span class="ruby-string">&quot;missing run or map statement&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">app</span>
  <span class="ruby-identifier">app</span> = <span class="ruby-ivar">@use</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-identifier">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">a</span>] }
  <span class="ruby-ivar">@warmup</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">app</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@warmup</span>
  <span class="ruby-identifier">app</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- to_app-source -->
            
          </div>

          

          
        </div><!-- to_app-method -->

      
        <div id="use-method" class="method-detail ">
          <a name="method-i-use"></a>

          
          <div class="method-heading">
            <span class="method-name">use</span><span
              class="method-args">(middleware, *args, &block)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Specifies middleware to use in a stack.</p>

<pre>class Middleware
  def initialize(app)
    @app = app
  end

  def call(env)
    env[&quot;rack.some_header&quot;] = &quot;setting an example&quot;
    @app.call(env)
  end
end

use Middleware
run lambda { |env| [200, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;OK&quot;]] }</pre>

<p>All requests through to this application will first be processed by the
middleware class. The <tt>call</tt> method in this example sets an
additional environment key which then can be referenced in the application
if required.</p>
            

            
            <div class="method-source-code" id="use-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 81</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">use</span>(<span class="ruby-identifier">middleware</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@map</span>
    <span class="ruby-identifier">mapping</span>, <span class="ruby-ivar">@map</span> = <span class="ruby-ivar">@map</span>, <span class="ruby-keyword">nil</span>
    <span class="ruby-ivar">@use</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">proc</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">app</span><span class="ruby-operator">|</span> <span class="ruby-identifier">generate_map</span> <span class="ruby-identifier">app</span>, <span class="ruby-identifier">mapping</span> }
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@use</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">proc</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-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>) }
<span class="ruby-keyword">end</span></pre>
            </div><!-- use-source -->
            
          </div>

          

          
        </div><!-- use-method -->

      
        <div id="warmup-method" class="method-detail ">
          <a name="method-i-warmup"></a>

          
          <div class="method-heading">
            <span class="method-name">warmup</span><span
              class="method-args">(prc=nil, &block)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Takes a lambda or block that is used to warm-up the application.</p>

<pre>warmup do |app|
  client = Rack::MockRequest.new(app)
  client.get('/')
end

use SomeMiddleware
run MyApp</pre>
            

            
            <div class="method-source-code" id="warmup-source">
<pre>
<span class="ruby-comment"># File lib/rack/builder.rb, line 116</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">warmup</span>(<span class="ruby-identifier">prc</span>=<span class="ruby-keyword">nil</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@warmup</span> = <span class="ruby-identifier">prc</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">block</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- warmup-source -->
            
          </div>

          

          
        </div><!-- warmup-method -->

      
      </div><!-- public-instance-method-details -->
    
    </div><!-- 5Buntitled-5D -->
  

  </div><!-- documentation -->

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>

</body>
</html>


Zerion Mini Shell 1.0