0
0
zero/doc/Zero/Response.html
2012-11-26 21:45:33 +01:00

723 lines
16 KiB
HTML

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Class: Zero::Response
&mdash; Documentation by YARD 0.8.3
</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
hasFrames = window.top.frames.main ? true : false;
relpath = '../';
framesUrl = "../frames.html#!" + escape(window.location.href);
</script>
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
</head>
<body>
<div id="header">
<div id="menu">
<a href="../_index.html">Index (R)</a> &raquo;
<span class='title'><span class='object_link'><a href="../Zero.html" title="Zero (module)">Zero</a></span></span>
&raquo;
<span class="title">Response</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../class_list.html">
Class List
</a>
<a class="full_list_link" id="method_list_link"
href="../method_list.html">
Method List
</a>
<a class="full_list_link" id="file_list_link"
href="../file_list.html">
File List
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><h1>Class: Zero::Response
</h1>
<dl class="box">
<dt class="r1">Inherits:</dt>
<dd class="r1">
<span class="inheritName">Object</span>
<ul class="fullTree">
<li>Object</li>
<li class="next">Zero::Response</li>
</ul>
<a href="#" class="inheritanceTree">show all</a>
</dd>
<dt class="r2 last">Defined in:</dt>
<dd class="r2 last">lib/zero/response.rb</dd>
</dl>
<div class="clear"></div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>This is the representation of a response</p>
</div>
</div>
<div class="tags">
</div>
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#body-instance_method" title="#body (instance method)">- (Object) <strong>body</strong> </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Returns the value of attribute body.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#header-instance_method" title="#header (instance method)">- (Object) <strong>header</strong> </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Returns the value of attribute header.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#status-instance_method" title="#status (instance method)">- (Object) <strong>status</strong> </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Returns the value of attribute status.</p>
</div></span>
</li>
</ul>
<h2>
Instance Method Summary
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#content_length-instance_method" title="#content_length (instance method)">- (Object) <strong>content_length</strong> </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Sets the content length header to the current length of the body Also
creates one, if it does not exists.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#content_type%3D-instance_method" title="#content_type= (instance method)">- (Object) <strong>content_type=</strong>(value) </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Sets the content type header to the given value Also creates it, if it does
not exists.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Response) <strong>initialize</strong> </a>
</span>
<span class="note title constructor">constructor</span>
<span class="summary_desc"><div class='inline'>
<p>Constructor Sets default status code to 200.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#to_a-instance_method" title="#to_a (instance method)">- (Array) <strong>to_a</strong> </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Returns the data of the response as an array:</p>
<dl class="rdoc-list label-list"><dt>status, header, body
<dd>
<p>to be usable by any webserver.</p>
</dd></dl>
</div></span>
</li>
</ul>
<div id="constructor_details" class="method_details_list">
<h2>Constructor Details</h2>
<div class="method_details first">
<h3 class="signature first" id="initialize-instance_method">
- (<tt><span class='object_link'><a href="" title="Zero::Response (class)">Response</a></span></tt>) <strong>initialize</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Constructor Sets default status code to 200.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
12
13
14
15
16</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/zero/response.rb', line 12</span>
<span class='rubyid_def def kw'>def</span> <span class='rubyid_initialize identifier id'>initialize</span>
<span class='rubyid_@status ivar id'>@status</span> <span class='assign token'>=</span> <span class='integer val'>200</span>
<span class='rubyid_@header ivar id'>@header</span> <span class='assign token'>=</span> <span class='lbrace token'>{</span><span class='rbrace token'>}</span>
<span class='rubyid_@body ivar id'>@body</span> <span class='assign token'>=</span> <span class='lbrack token'>[</span><span class='rbrack token'>]</span>
<span class='rubyid_end end kw'>end</span>
</pre>
</td>
</tr>
</table>
</div>
</div>
<div id="instance_attr_details" class="attr_details">
<h2>Instance Attribute Details</h2>
<span id="body=-instance_method"></span>
<div class="method_details first">
<h3 class="signature first" id="body-instance_method">
- (<tt>Object</tt>) <strong>body</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Returns the value of attribute body</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
7
8
9</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/zero/response.rb', line 7</span>
<span class='rubyid_def def kw'>def</span> <span class='rubyid_body identifier id'>body</span>
<span class='rubyid_@body ivar id'>@body</span>
<span class='rubyid_end end kw'>end</span>
</pre>
</td>
</tr>
</table>
</div>
<span id="header=-instance_method"></span>
<div class="method_details ">
<h3 class="signature " id="header-instance_method">
- (<tt>Object</tt>) <strong>header</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Returns the value of attribute header</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
7
8
9</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/zero/response.rb', line 7</span>
<span class='rubyid_def def kw'>def</span> <span class='rubyid_header identifier id'>header</span>
<span class='rubyid_@header ivar id'>@header</span>
<span class='rubyid_end end kw'>end</span>
</pre>
</td>
</tr>
</table>
</div>
<span id="status=-instance_method"></span>
<div class="method_details ">
<h3 class="signature " id="status-instance_method">
- (<tt>Object</tt>) <strong>status</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Returns the value of attribute status</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
6
7
8</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/zero/response.rb', line 6</span>
<span class='rubyid_def def kw'>def</span> <span class='rubyid_status identifier id'>status</span>
<span class='rubyid_@status ivar id'>@status</span>
<span class='rubyid_end end kw'>end</span>
</pre>
</td>
</tr>
</table>
</div>
</div>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="content_length-instance_method">
- (<tt>Object</tt>) <strong>content_length</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Sets the content length header to the current length of the body Also
creates one, if it does not exists</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
57
58
59</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/zero/response.rb', line 57</span>
<span class='rubyid_def def kw'>def</span> <span class='rubyid_content_length identifier id'>content_length</span>
<span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_header identifier id'>header</span><span class='lbrack token'>[</span><span class='string val'>'Content-Length'</span><span class='rbrack token'>]</span> <span class='assign token'>=</span> <span class='rubyid_body identifier id'>body</span><span class='dot token'>.</span><span class='rubyid_join identifier id'>join</span><span class='dot token'>.</span><span class='rubyid_bytesize identifier id'>bytesize</span><span class='dot token'>.</span><span class='rubyid_to_s identifier id'>to_s</span>
<span class='rubyid_end end kw'>end</span>
</pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="content_type=-instance_method">
- (<tt>Object</tt>) <strong>content_type=</strong>(value)
</h3><div class="docstring">
<div class="discussion">
<p>Sets the content type header to the given value Also creates it, if it does
not exists</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>value</span>
<span class='type'>(<tt>String</tt>)</span>
&mdash;
<div class='inline'>
<p>Content-Type tp set</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
66
67
68</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/zero/response.rb', line 66</span>
<span class='rubyid_def def kw'>def</span> <span class='rubyid_content_type= identifier id'>content_type=</span><span class='lparen token'>(</span><span class='rubyid_value identifier id'>value</span><span class='rparen token'>)</span>
<span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_header identifier id'>header</span><span class='lbrack token'>[</span><span class='string val'>'Content-Type'</span><span class='rbrack token'>]</span> <span class='assign token'>=</span> <span class='rubyid_value identifier id'>value</span>
<span class='rubyid_end end kw'>end</span>
</pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="to_a-instance_method">
- (<tt>Array</tt>) <strong>to_a</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Returns the data of the response as an array:</p>
<dl class="rdoc-list label-list"><dt>status, header, body
<dd>
<p>to be usable by any webserver.</p>
<p>Sets the Content-Type to 'text/html', if it's not already set. Sets the
Content-Length, if it's not already set. (Won't fix wrong lengths!) Removes
Content-Type, Content-Length and body on status code 204 and 304.</p>
</dd></dl>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Array</tt>)</span>
&mdash;
<div class='inline'>
<p>Usable by webservers</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/zero/response.rb', line 38</span>
<span class='rubyid_def def kw'>def</span> <span class='rubyid_to_a identifier id'>to_a</span>
<span class='comment val'># Remove content length and body, on status 204 and 304</span>
<span class='rubyid_if if kw'>if</span> <span class='rubyid_status identifier id'>status</span> <span class='eq op'>==</span> <span class='integer val'>204</span> <span class='rubyid_or or kw'>or</span> <span class='rubyid_status identifier id'>status</span> <span class='eq op'>==</span> <span class='integer val'>304</span>
<span class='rubyid_header identifier id'>header</span><span class='dot token'>.</span><span class='rubyid_delete identifier id'>delete</span><span class='lparen token'>(</span><span class='string val'>'Content-Length'</span><span class='rparen token'>)</span>
<span class='rubyid_header identifier id'>header</span><span class='dot token'>.</span><span class='rubyid_delete identifier id'>delete</span><span class='lparen token'>(</span><span class='string val'>'Content-Type'</span><span class='rparen token'>)</span>
<span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_body identifier id'>body</span> <span class='assign token'>=</span> <span class='lbrack token'>[</span><span class='rbrack token'>]</span>
<span class='rubyid_else else kw'>else</span>
<span class='comment val'># Set content length, if not already set</span>
<span class='rubyid_content_length identifier id'>content_length</span> <span class='rubyid_unless unless_mod kw'>unless</span> <span class='rubyid_header identifier id'>header</span><span class='dot token'>.</span><span class='rubyid_has_key? fid id'>has_key?</span> <span class='string val'>'Content-Length'</span>
<span class='comment val'># Set content type, if not already set</span>
<span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_content_type identifier id'>content_type</span> <span class='assign token'>=</span> <span class='string val'>'text/html'</span> <span class='rubyid_unless unless_mod kw'>unless</span> <span class='rubyid_header identifier id'>header</span><span class='dot token'>.</span><span class='rubyid_has_key? fid id'>has_key?</span> <span class='string val'>'Content-Type'</span>
<span class='rubyid_end end kw'>end</span>
<span class='lbrack token'>[</span><span class='rubyid_status identifier id'>status</span><span class='comma token'>,</span> <span class='rubyid_header identifier id'>header</span><span class='comma token'>,</span> <span class='rubyid_body identifier id'>body</span><span class='rbrack token'>]</span>
<span class='rubyid_end end kw'>end</span>
</pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Mon Nov 26 21:45:20 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.3 (ruby-1.9.3).
</div>
</body>
</html>