instiki/vendor/plugins/rack/doc/classes/Rack/Reloader.html
Jacques Distler 4e14ccc74d Instiki 0.16.3: Rails 2.3.0
Instiki now runs on the Rails 2.3.0 Candidate Release.
Among other improvements, this means that it now 
automagically selects between WEBrick and Mongrel.

Just run

    ./instiki --daemon
2009-02-04 14:26:08 -06:00

249 lines
11 KiB
HTML

<?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::Reloader</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::Reloader</td>
</tr>
<tr class="top-aligned-row">
<td><strong>In:</strong></td>
<td>
<a href="../../files/lib/rack/reloader_rb.html">
lib/rack/reloader.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="Reloader.html">Rack::Reloader</a> checks on every request, but at
most every <tt>secs</tt> seconds, if a file loaded changed, and reloads it,
logging to rack.errors.
</p>
<p>
It is recommended you use <a href="ShowExceptions.html">ShowExceptions</a>
to catch SyntaxErrors etc.
</p>
</div>
</div>
<div id="method-list">
<h3 class="section-bar">Methods</h3>
<div class="name-list">
<a href="#M000133">call</a>&nbsp;&nbsp;
<a href="#M000132">new</a>&nbsp;&nbsp;
<a href="#M000134">reload!</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-M000132" class="method-detail">
<a name="M000132"></a>
<div class="method-heading">
<a href="#M000132" class="method-signature">
<span class="method-name">new</span><span class="method-args">(app, secs=10)</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000132-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000132-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/reloader.rb, line 11</span>
11: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">app</span>, <span class="ruby-identifier">secs</span>=<span class="ruby-value">10</span>)
12: <span class="ruby-ivar">@app</span> = <span class="ruby-identifier">app</span>
13: <span class="ruby-ivar">@secs</span> = <span class="ruby-identifier">secs</span> <span class="ruby-comment cmt"># reload every @secs seconds max</span>
14: <span class="ruby-ivar">@last</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
15: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<h3 class="section-bar">Public Instance methods</h3>
<div id="method-M000133" class="method-detail">
<a name="M000133"></a>
<div class="method-heading">
<a href="#M000133" 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('M000133-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000133-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/reloader.rb, line 17</span>
17: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
18: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span> <span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@last</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@secs</span>
19: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">exclusive</span> {
20: <span class="ruby-identifier">reload!</span>(<span class="ruby-identifier">env</span>[<span class="ruby-value str">'rack.errors'</span>])
21: <span class="ruby-ivar">@last</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
22: }
23: <span class="ruby-keyword kw">end</span>
24:
25: <span class="ruby-ivar">@app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
26: <span class="ruby-keyword kw">end</span>
</pre>
</div>
</div>
</div>
<div id="method-M000134" class="method-detail">
<a name="M000134"></a>
<div class="method-heading">
<a href="#M000134" class="method-signature">
<span class="method-name">reload!</span><span class="method-args">(stderr=STDERR)</span>
</a>
</div>
<div class="method-description">
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000134-source');return false;">[Source]</a></p>
<div class="method-source-code" id="M000134-source">
<pre>
<span class="ruby-comment cmt"># File lib/rack/reloader.rb, line 28</span>
28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload!</span>(<span class="ruby-identifier">stderr</span>=<span class="ruby-constant">STDERR</span>)
29: <span class="ruby-identifier">need_reload</span> = <span class="ruby-identifier">$LOADED_FEATURES</span>.<span class="ruby-identifier">find_all</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">loaded</span><span class="ruby-operator">|</span>
30: <span class="ruby-keyword kw">begin</span>
31: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">loaded</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\A[.\/]/</span> <span class="ruby-comment cmt"># absolute filename or 1.9</span>
32: <span class="ruby-identifier">abs</span> = <span class="ruby-identifier">loaded</span>
33: <span class="ruby-keyword kw">else</span>
34: <span class="ruby-identifier">abs</span> = <span class="ruby-identifier">$LOAD_PATH</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> <span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">loaded</span>) }.
35: <span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span> <span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-identifier">file</span> }
36: <span class="ruby-keyword kw">end</span>
37:
38: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">abs</span>
39: <span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">abs</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@last</span> <span class="ruby-operator">-</span> <span class="ruby-ivar">@secs</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">false</span>
40: <span class="ruby-keyword kw">else</span>
41: <span class="ruby-keyword kw">false</span>
42: <span class="ruby-keyword kw">end</span>
43: <span class="ruby-keyword kw">end</span>
44: }
45:
46: <span class="ruby-identifier">need_reload</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span>
47: <span class="ruby-identifier">$LOADED_FEATURES</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">l</span>
48: }
49:
50: <span class="ruby-identifier">need_reload</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">to_load</span><span class="ruby-operator">|</span>
51: <span class="ruby-keyword kw">begin</span>
52: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">require</span> <span class="ruby-identifier">to_load</span>
53: <span class="ruby-identifier">stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{self.class}: reloaded `#{to_load}'&quot;</span>
54: <span class="ruby-keyword kw">end</span>
55: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>, <span class="ruby-constant">SyntaxError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
56: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span> <span class="ruby-comment cmt"># Possibly ShowExceptions</span>
57: <span class="ruby-keyword kw">end</span>
58: }
59:
60: <span class="ruby-identifier">stderr</span>.<span class="ruby-identifier">flush</span>
61: <span class="ruby-identifier">need_reload</span>
62: <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>