From 37a4a28deec224f7cd9a5a124e22258e868913e4 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Mon, 26 Nov 2012 21:40:21 +0100 Subject: added the first set of documentation --- doc/Zero/Response.html | 723 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 723 insertions(+) create mode 100644 doc/Zero/Response.html (limited to 'doc/Zero/Response.html') diff --git a/doc/Zero/Response.html b/doc/Zero/Response.html new file mode 100644 index 0000000..6ed9127 --- /dev/null +++ b/doc/Zero/Response.html @@ -0,0 +1,723 @@ + + + + + + Class: Zero::Response + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Response + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/zero/response.rb
+ +
+
+ +

Overview

+
+ +

This is the representation of a response

+ + +
+
+
+ + +
+ + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Response) initialize + + + + + +

+
+ +

Constructor Sets default status code to 200.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+12
+13
+14
+15
+16
+
+
# File 'lib/zero/response.rb', line 12
+
+def initialize
+  @status = 200
+  @header = {}
+  @body   = []
+end
+
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) body + + + + + +

+
+ +

Returns the value of attribute body

+ + +
+
+
+ + +
+ + + + +
+
+
+
+7
+8
+9
+
+
# File 'lib/zero/response.rb', line 7
+
+def body
+  @body
+end
+
+
+
+ + + +
+

+ + - (Object) header + + + + + +

+
+ +

Returns the value of attribute header

+ + +
+
+
+ + +
+ + + + +
+
+
+
+7
+8
+9
+
+
# File 'lib/zero/response.rb', line 7
+
+def header
+  @header
+end
+
+
+
+ + + +
+

+ + - (Object) status + + + + + +

+
+ +

Returns the value of attribute status

+ + +
+
+
+ + +
+ + + + +
+
+
+
+6
+7
+8
+
+
# File 'lib/zero/response.rb', line 6
+
+def status
+  @status
+end
+
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) content_length + + + + + +

+
+ +

Sets the content length header to the current length of the body Also +creates one, if it does not exists

+ + +
+
+
+ + +
+ + + + +
+
+
+
+57
+58
+59
+
+
# File 'lib/zero/response.rb', line 57
+
+def content_length
+  self.header['Content-Length'] = body.join.bytesize.to_s
+end
+
+
+
+ +
+

+ + - (Object) content_type=(value) + + + + + +

+
+ +

Sets the content type header to the given value Also creates it, if it does +not exists

+ + +
+
+
+

Parameters:

+
    + +
  • + + value + + + (String) + + + + — +
    +

    Content-Type tp set

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+66
+67
+68
+
+
# File 'lib/zero/response.rb', line 66
+
+def content_type=(value)
+  self.header['Content-Type'] = value
+end
+
+
+
+ +
+

+ + - (Array) to_a + + + + + +

+
+ +

Returns the data of the response as an array:

+
status, header, body +
+

to be usable by any webserver.

+ +

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.

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array) + + + + — +
    +

    Usable by webservers

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+
+
# File 'lib/zero/response.rb', line 38
+
+def to_a
+  # Remove content length and body, on status 204 and 304
+  if status == 204 or status == 304
+    header.delete('Content-Length')
+    header.delete('Content-Type')
+    self.body = []
+  else
+    # Set content length, if not already set
+    content_length unless header.has_key? 'Content-Length'
+    # Set content type, if not already set
+    self.content_type = 'text/html' unless header.has_key? 'Content-Type'
+  end
+
+  [status, header, body]
+end
+
+
+
+ +
+ +
+ + + + + \ No newline at end of file -- cgit v1.2.3-70-g09d2