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/Controller.html | 616 ++++++++++++++++ doc/Zero/FileNotFoundError.html | 123 ++++ doc/Zero/Renderer.html | 654 +++++++++++++++++ doc/Zero/Request.html | 1476 ++++++++++++++++++++++++++++++++++++++ doc/Zero/Request/Accept.html | 612 ++++++++++++++++ doc/Zero/Request/AcceptType.html | 403 +++++++++++ doc/Zero/Request/Client.html | 579 +++++++++++++++ doc/Zero/Request/Parameter.html | 489 +++++++++++++ doc/Zero/Request/Server.html | 687 ++++++++++++++++++ doc/Zero/Response.html | 723 +++++++++++++++++++ doc/Zero/Router.html | 333 +++++++++ 11 files changed, 6695 insertions(+) create mode 100644 doc/Zero/Controller.html create mode 100644 doc/Zero/FileNotFoundError.html create mode 100644 doc/Zero/Renderer.html create mode 100644 doc/Zero/Request.html create mode 100644 doc/Zero/Request/Accept.html create mode 100644 doc/Zero/Request/AcceptType.html create mode 100644 doc/Zero/Request/Client.html create mode 100644 doc/Zero/Request/Parameter.html create mode 100644 doc/Zero/Request/Server.html create mode 100644 doc/Zero/Response.html create mode 100644 doc/Zero/Router.html (limited to 'doc/Zero') diff --git a/doc/Zero/Controller.html b/doc/Zero/Controller.html new file mode 100644 index 0000000..a4e6a0c --- /dev/null +++ b/doc/Zero/Controller.html @@ -0,0 +1,616 @@ + + + + + + Class: Zero::Controller + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Controller + + + +

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

Overview

+
+ +

abstract class to make creation of controllers easier

+ +

This abstract class creates an interface to make it easier to write rack +compatible controllers. It catches #call and creates a new instance with +the environment and calls #render on it.

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

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Controller) initialize(request) + + + + + +

+
+ +

initialize the controller

+ + +
+
+
+

Parameters:

+
    + +
  • + + request + + + (Request) + + + + — +
    +

    a request object

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+30
+31
+32
+33
+
+
# File 'lib/zero/controller.rb', line 30
+
+def initialize(request)
+  @request  = request
+  @response = Zero::Response.new
+end
+
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) call(env) + + + + + +

+
+ +

initialize a new instance of the controller and call response on it

+ + +
+
+
+ + +
+ + + + +
+
+
+
+9
+10
+11
+
+
# File 'lib/zero/controller.rb', line 9
+
+def self.call(env)
+  new(Zero::Request.new(env)).response
+end
+
+
+
+ +
+

+ + + (Object) renderer + + + + + +

+
+ +

get the renderer set in the controller

+ + +
+
+
+ + +
+ + + + +
+
+
+
+19
+20
+21
+
+
# File 'lib/zero/controller.rb', line 19
+
+def self.renderer
+  @@renderer
+end
+
+
+
+ +
+

+ + + (Object) renderer=(renderer) + + + + + +

+
+ +

set the renderer to use in the controller

+ + +
+
+
+ + +
+ + + + +
+
+
+
+14
+15
+16
+
+
# File 'lib/zero/controller.rb', line 14
+
+def self.renderer=(renderer)
+  @@renderer = renderer
+end
+
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + - (Object) renderer + + + + + +

+
+ +

a small helper to get the actual renderer

+ + +
+
+
+ + +
+ + + + +
+
+
+
+24
+25
+26
+
+
# File 'lib/zero/controller.rb', line 24
+
+def renderer
+  self.class.renderer
+end
+
+
+
+ +
+

+ + - (Object) response + + + + + +

+
+ +

build the response and return it

+ +

This method calls #process if it was defined so make it easier to process +the request before rendering stuff.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + + + + + +
    +

    Response a rack conform response

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+40
+41
+42
+43
+44
+
+
# File 'lib/zero/controller.rb', line 40
+
+def response
+  process if respond_to?(:process)
+  render
+  @response.to_a
+end
+
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/doc/Zero/FileNotFoundError.html b/doc/Zero/FileNotFoundError.html new file mode 100644 index 0000000..4515a76 --- /dev/null +++ b/doc/Zero/FileNotFoundError.html @@ -0,0 +1,123 @@ + + + + + + Exception: Zero::FileNotFoundError + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Exception: Zero::FileNotFoundError + + + +

+ +
+ +
Inherits:
+
+ IOError + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/zero/renderer.rb
+ +
+
+ + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/doc/Zero/Renderer.html b/doc/Zero/Renderer.html new file mode 100644 index 0000000..4ce1cee --- /dev/null +++ b/doc/Zero/Renderer.html @@ -0,0 +1,654 @@ + + + + + + Class: Zero::Renderer + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Renderer + + + +

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

Overview

+
+ +

This class helps with rendering of content.

+ +

The purpose of this class is to render templates. All variables pushed into +the renderer should be already processed, so that the raw data can be used.

+ +

The workflow of this class is like the following.

+
  • +

    setup the type mapping

    +
  • +

    create a new instance of the class to prepare rendering

    +
  • +

    call #render to process the template

    +
+ +

The call to #render will return the String representation of the template +with all data given.

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

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Renderer) initialize(path, context, accept_types) + + + + + +

+
+ +

take the path and render the template within the context

+ + +
+
+
+

Parameters:

+
    + +
  • + + path + + + (String) + + + + — +
    +

    the relative path to the template

    +
    + +
  • + +
  • + + context + + + (Object) + + + + — +
    +

    the object to process on

    +
    + +
  • + +
  • + + accept_types + + + + + + +
  • + +
+ + +
+ + + + +
+
+
+
+49
+50
+51
+52
+53
+
+
# File 'lib/zero/renderer.rb', line 49
+
+def initialize(path, context, accept_types)
+  accept_types ||= Request::Accept.new('text/html')
+  @path    = find_template(path, accept_types)
+  @context = context
+end
+
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) template_path=(path) + + + + + +

+
+ +

set a base path for template search

+ + +
+
+
+

Parameters:

+
    + +
  • + + path + + + (String) + + + + — +
    +

    the path to the template base dir

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+20
+21
+22
+
+
# File 'lib/zero/renderer.rb', line 20
+
+def template_path=(path)
+  @@path = path + '/'
+end
+
+
+
+ +
+

+ + + (Hash) type_map + + + + + +

+
+ +

returns the type map

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash) + + + + — +
    +

    the mapping for types

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+40
+41
+42
+
+
# File 'lib/zero/renderer.rb', line 40
+
+def type_map
+  @@map ||= {}
+end
+
+
+
+ +
+

+ + + (Object) type_map=(map) + + + + + +

+
+ +

save a mapping hash for the type

+ +

With that it is possible to map long and complex contant types to simpler +representations. These get then used in the finding process for the best +fitting template.

+ + +
+
+
+ +
+

Examples:

+ + +
Zero::Renderer.map = {'text/html' => 'html'}
+
+ +
+

Parameters:

+
    + +
  • + + map + + + (Hash) + + + + — +
    +

    maps the content type to a simple representation

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+34
+35
+36
+
+
# File 'lib/zero/renderer.rb', line 34
+
+def type_map=(map)
+  @@map = map
+end
+
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + - (String) render + + + + + +

+
+ +

render the template within the context

+ + +
+
+
+ +

Returns:

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

    the rendered template

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+57
+58
+59
+
+
# File 'lib/zero/renderer.rb', line 57
+
+def render
+  Tilt.new(@path).render(@context)
+end
+
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/doc/Zero/Request.html b/doc/Zero/Request.html new file mode 100644 index 0000000..03e5591 --- /dev/null +++ b/doc/Zero/Request.html @@ -0,0 +1,1476 @@ + + + + + + Class: Zero::Request + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Request + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/zero/request.rb,
+ lib/zero/request/server.rb,
lib/zero/request/client.rb,
lib/zero/request/accept.rb,
lib/zero/request/parameter.rb,
lib/zero/request/accept_type.rb
+
+ +
+
+ +

Overview

+
+ +

This class wraps around a rack environment for easier access to all data.

+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + + + Classes: Accept, AcceptType, Client, Parameter, Server + + +

+ +

Constant Summary

+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Request) initialize(env) + + + + + +

+
+ +

create a new request object

+ + +
+
+
+ + +
+ + + + +
+
+
+
+15
+16
+17
+18
+
+
# File 'lib/zero/request.rb', line 15
+
+def initialize(env)
+  @env = env
+  @env['zero.request'] = self
+end
+
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Hash) env (readonly) + + + + + +

+
+ +

get the environment

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash) + + + + — +
    +

    the environment hash

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+22
+23
+24
+
+
# File 'lib/zero/request.rb', line 22
+
+def env
+  @env
+end
+
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) create(environment) + + + + + +

+ + + + +
+
+
+
+9
+10
+11
+12
+
+
# File 'lib/zero/request.rb', line 9
+
+def self.create(environment)
+  return environment['zero.request'] if environment.has_key?('zero.request')
+  new(environment)
+end
+
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + - (Accept) accept + + + + + +

+
+ +

get the media types

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Accept) + + + + — +
    +

    on Accept object managing all types and their order

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+57
+58
+59
+
+
# File 'lib/zero/request.rb', line 57
+
+def accept
+  @accept ||= Request::Accept.new(@env)
+end
+
+
+
+ +
+

+ + - (Client) client + + + + + +

+
+ +

return all information about the client

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Client) + + + + — +
    +

    an information object about the client

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+32
+33
+34
+
+
# File 'lib/zero/request.rb', line 32
+
+def client
+  @client ||= Request::Client.new(@env)
+end
+
+
+
+ +
+

+ + - (String) content_type + + + + + +

+
+ +

return the content type of the request TODO change into its own object?

+ + +
+
+
+ +

Returns:

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

    returns the content type of the request

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+51
+52
+53
+
+
# File 'lib/zero/request.rb', line 51
+
+def content_type
+  @env[CONST_CONTENT_TYPE] if @env.has_key?(CONST_CONTENT_TYPE)
+end
+
+
+
+ +
+

+ + - (Boolean) delete? + + + + + +

+
+ +

is the method 'DELETE'?

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true if this is a delete request

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+77
+
+
# File 'lib/zero/request.rb', line 77
+
+def delete?; method == :delete end
+
+
+
+ +
+

+ + - (Boolean) get? + + + + + +

+
+ +

is the method 'GET'?

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true if this is a get request

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+68
+
+
# File 'lib/zero/request.rb', line 68
+
+def get?;  method == :get  end
+
+
+
+ +
+

+ + - (Boolean) head? + + + + + +

+
+ +

is the method 'HEAD'?

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true if this is a head request

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+80
+
+
# File 'lib/zero/request.rb', line 80
+
+def head?; method == :head end
+
+
+
+ +
+

+ + - (Symbol) method + + + + + +

+
+ +

get the method of the request

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Symbol) + + + + — +
    +

    the symbol representation of the method

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+63
+64
+65
+
+
# File 'lib/zero/request.rb', line 63
+
+def method
+  @method ||= @env[CONST_REQUEST_METHOD].downcase.to_sym
+end
+
+
+
+ +
+

+ + - (Parameter) params + + + + + +

+
+ +

get an object representing the parameters of the request

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Parameter) + + + + — +
    +

    object having all parameters

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+44
+45
+46
+
+
# File 'lib/zero/request.rb', line 44
+
+def params
+  @params ||= Request::Parameter.new(@env)
+end
+
+
+
+ +
+

+ + - (Boolean) patch? + + + + + +

+
+ +

is the method 'PATCH'?

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true if this is a patch request

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+83
+
+
# File 'lib/zero/request.rb', line 83
+
+def patch?; method == :patch end
+
+
+
+ +
+

+ + - (String) path + + + + + +

+
+ +

get the requested path

+ + +
+
+
+ +

Returns:

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

    returns the requested path

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+26
+27
+28
+
+
# File 'lib/zero/request.rb', line 26
+
+def path
+  @path ||= @env[CONST_PATH_INFO]
+end
+
+
+
+ +
+

+ + - (Boolean) post? + + + + + +

+
+ +

is the method 'POST'?

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true if this is a post request

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+71
+
+
# File 'lib/zero/request.rb', line 71
+
+def post?; method == :post end
+
+
+
+ +
+

+ + - (Boolean) put? + + + + + +

+
+ +

is the method 'PUT'?

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true if this is a put request

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+74
+
+
# File 'lib/zero/request.rb', line 74
+
+def put?;  method == :put  end
+
+
+
+ +
+

+ + - (Server) server + + + + + +

+
+ +

get the information on the server

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Server) + + + + — +
    +

    information on the running server

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+38
+39
+40
+
+
# File 'lib/zero/request.rb', line 38
+
+def server
+  @server ||= Request::Server.new(@env)
+end
+
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/doc/Zero/Request/Accept.html b/doc/Zero/Request/Accept.html new file mode 100644 index 0000000..8a45ae0 --- /dev/null +++ b/doc/Zero/Request/Accept.html @@ -0,0 +1,612 @@ + + + + + + Class: Zero::Request::Accept + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Request::Accept + + + +

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

Overview

+
+ +

encapsulates the accept header to easier work with this is partly copied +from sinatra

+ + +
+
+
+ + +
+

Constant Summary

+ +
+ +
MEDIA_TYPE_SEPERATOR = + +
+
','
+
+ +
MEDIA_PARAM_SEPERATOR = + +
+
';'
+
+ +
MEDIA_QUALITY_REGEX = + +
+
/q=[01]\./
+
+ +
KEY_HTTP_ACCEPT = + +
+
'HTTP_ACCEPT'
+
+ +
KEY_HTTP_ACCEPT_LANGUAGE = + +
+
'HTTP_ACCEPT_LANGUAGE'
+
+ +
KEY_HTTP_ACCEPT_ENCODING = + +
+
'HTTP_ACCEPT_ENCODING'
+
+ +
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Accept) initialize(environment) + + + + + +

+
+ +

create a new accept object

+ + +
+
+
+ + +
+ + + + +
+
+
+
+25
+26
+27
+28
+29
+
+
# File 'lib/zero/request/accept.rb', line 25
+
+def initialize(environment)
+  @types = AcceptType.new(environment[KEY_HTTP_ACCEPT])
+  @language = AcceptType.new(environment[KEY_HTTP_ACCEPT_LANGUAGE])
+  @encoding = AcceptType.new(environment[KEY_HTTP_ACCEPT_ENCODING])
+end
+
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) encoding (readonly) + + + + + +

+
+ +

Returns the value of attribute encoding

+ + +
+
+
+ + +
+ + + + +
+
+
+
+33
+34
+35
+
+
# File 'lib/zero/request/accept.rb', line 33
+
+def encoding
+  @encoding
+end
+
+
+
+ + + +
+

+ + - (Object) language (readonly) + + + + + +

+
+ +

Returns the value of attribute language

+ + +
+
+
+ + +
+ + + + +
+
+
+
+32
+33
+34
+
+
# File 'lib/zero/request/accept.rb', line 32
+
+def language
+  @language
+end
+
+
+
+ + + +
+

+ + - (Object) types (readonly) + + + + + +

+
+ +

Returns the value of attribute types

+ + +
+
+
+ + +
+ + + + +
+
+
+
+31
+32
+33
+
+
# File 'lib/zero/request/accept.rb', line 31
+
+def types
+  @types
+end
+
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) map + + + + + +

+ + + + +
+
+
+
+20
+21
+22
+
+
# File 'lib/zero/request/accept.rb', line 20
+
+def self.map
+  @@map ||= {}
+end
+
+
+
+ +
+

+ + + (Object) map=(map) + + + + + +

+ + + + +
+
+
+
+16
+17
+18
+
+
# File 'lib/zero/request/accept.rb', line 16
+
+def self.map=(map)
+  @@map = map
+end
+
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/doc/Zero/Request/AcceptType.html b/doc/Zero/Request/AcceptType.html new file mode 100644 index 0000000..603d3d3 --- /dev/null +++ b/doc/Zero/Request/AcceptType.html @@ -0,0 +1,403 @@ + + + + + + Class: Zero::Request::AcceptType + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Request::AcceptType + + + +

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

Overview

+
+ +

This class provides an interface to access information of accept schemas.

+ + +
+
+
+ + +
+

Constant Summary

+ +
+ +
MEDIA_TYPE_SEPERATOR = + +
+
','
+
+ +
MEDIA_PARAM_SEPERATOR = + +
+
';'
+
+ +
MEDIA_QUALITY_REGEX = + +
+
/q=[01]\./
+
+ +
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (AcceptType) initialize(string) + + + + + +

+
+ +

create a new instance of AcceptType

+ + +
+
+
+ + +
+ + + + +
+
+
+
+10
+11
+12
+13
+14
+15
+16
+
+
# File 'lib/zero/request/accept_type.rb', line 10
+
+def initialize(string)
+  if string.nil?
+    @elements = []
+  else
+    @elements = parse_elements(string)
+  end
+end
+
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) each + + + + + +

+
+ +

iterate over all media types

+ + +
+
+
+ + +
+ + + + +
+
+
+
+25
+26
+27
+
+
# File 'lib/zero/request/accept_type.rb', line 25
+
+def each
+  @elements.each {|element| yield element}
+end
+
+
+
+ +
+

+ + - (Object) preferred + + + + + +

+
+ +

return the preferred type

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + + + + + +
    +

    String the preferred media type

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+20
+21
+22
+
+
# File 'lib/zero/request/accept_type.rb', line 20
+
+def preferred
+  @elements.first
+end
+
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/doc/Zero/Request/Client.html b/doc/Zero/Request/Client.html new file mode 100644 index 0000000..f2e733d --- /dev/null +++ b/doc/Zero/Request/Client.html @@ -0,0 +1,579 @@ + + + + + + Class: Zero::Request::Client + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Request::Client + + + +

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

Overview

+
+ +

This class represents all information about the client of a request.

+ + +
+
+
+ + +
+

Constant Summary

+ +
+ +
KEY_REMOTE_ADDR = +
+
+ +

the key for the ip of the client

+ + +
+
+
+ + +
+
+
'REMOTE_ADDR'
+
+ +
KEY_REMOTE_HOST = +
+
+ +

the key for the hostname

+ + +
+
+
+ + +
+
+
'REMOTE_HOST'
+
+ +
KEY_USER_AGENT = +
+
+ +

the key for the user agent

+ + +
+
+
+ + +
+
+
'HTTP_USER_AGENT'
+
+ +
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Client) initialize(environment) + + + + + +

+
+ +

creates a new client with the data of the request environment

+ + +
+
+
+

Parameters:

+
    + +
  • + + environment + + + + + + + — +
    +

    a hash representation of the request

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+14
+15
+16
+17
+18
+
+
# File 'lib/zero/request/client.rb', line 14
+
+def initialize(environment)
+  @address    = environment[KEY_REMOTE_ADDR]
+  @hostname   = environment[KEY_REMOTE_HOST]
+  @user_agent = environment[KEY_USER_AGENT]
+end
+
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (String) address (readonly) + + + + + +

+
+ +

the ip address of the client

+ + +
+
+
+ +

Returns:

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

    the address of the client

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+22
+23
+24
+
+
# File 'lib/zero/request/client.rb', line 22
+
+def address
+  @address
+end
+
+
+
+ + + +
+

+ + - (String) hostname (readonly) + + + + + +

+
+ +

the hostname of the client

+ + +
+
+
+ +

Returns:

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

    the hostname of the client

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+25
+26
+27
+
+
# File 'lib/zero/request/client.rb', line 25
+
+def hostname
+  @hostname
+end
+
+
+
+ + + +
+

+ + - (String) user_agent (readonly) + + + + + +

+
+ +

the user agent of the client

+ + +
+
+
+ +

Returns:

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

    the user agent of the client

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+28
+29
+30
+
+
# File 'lib/zero/request/client.rb', line 28
+
+def user_agent
+  @user_agent
+end
+
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/doc/Zero/Request/Parameter.html b/doc/Zero/Request/Parameter.html new file mode 100644 index 0000000..e8c170c --- /dev/null +++ b/doc/Zero/Request/Parameter.html @@ -0,0 +1,489 @@ + + + + + + Class: Zero::Request::Parameter + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Request::Parameter + + + +

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

Overview

+
+ +

represents all parameter set in a session

+ +

This class holds all parameters available in the rack environment, split on +query and payload parameters.

+ + +
+
+
+ + +
+

Constant Summary

+ +
+ +
ENV_KEY_QUERY = +
+
+ +

they key for the query string

+ + +
+
+
+ + +
+
+
'QUERY_STRING'
+
+ +
ENV_KEY_PAYLOAD = +
+
+ +

the key for the payload

+ + +
+
+
+ + +
+
+
'rack.input'
+
+ +
ENV_KEY_CONTENT_TYPE = +
+
+ +

the key for the content type

+ + +
+
+
+ + +
+
+
'CONTENT_TYPE'
+
+ +
PAYLOAD_CONTENT_TYPES = +
+
+ +

all content types which used for using the body as a parameter input

+ + +
+
+
+ + +
+
+
[
+  'application/x-www-form-urlencoded',
+  'multipart/form-data'
+].to_set
+
+ +
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Parameter) initialize(environment) + + + + + +

+
+ +

creates a new parameter instance

+ +

This should never be called directly, as it will be generated for you. This +instance gives you the options to get query parameters (mostly called GET +parameters) and payload parameters (or POST parameters).

+ + +
+
+
+

Parameters:

+
    + +
  • + + environment + + + (Hash) + + + + — +
    +

    the rack environment

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+37
+38
+39
+40
+
+
# File 'lib/zero/request/parameter.rb', line 37
+
+def initialize(environment)
+  @query   = extract_query_params(environment)
+  @payload = extract_payload_params(environment)
+end
+
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) payload (readonly) + + + + Also known as: + post + + + + +

+
+ +

get the payload or form data parameters

+ + +
+
+
+ + +
+ + + + +
+
+
+
+28
+29
+30
+
+
# File 'lib/zero/request/parameter.rb', line 28
+
+def payload
+  @payload
+end
+
+
+
+ + + +
+

+ + - (Object) query (readonly) + + + + Also known as: + get + + + + +

+
+ +

get the query parameters

+ + +
+
+
+ + +
+ + + + +
+
+
+
+24
+25
+26
+
+
# File 'lib/zero/request/parameter.rb', line 24
+
+def query
+  @query
+end
+
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/doc/Zero/Request/Server.html b/doc/Zero/Request/Server.html new file mode 100644 index 0000000..2a187d8 --- /dev/null +++ b/doc/Zero/Request/Server.html @@ -0,0 +1,687 @@ + + + + + + Class: Zero::Request::Server + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Request::Server + + + +

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

Overview

+
+ +

This class represents all server related information of a request.

+ + +
+
+
+ + +
+

Constant Summary

+ +
+ +
KEY_SERVER_NAME = +
+
+

+ This constant is part of a private API. + You should avoid using this constant if possible, as it may be removed or be changed in the future. +

+ +

the key for the server name

+ + +
+
+
+ + +
+
+
'SERVER_NAME'
+
+ +
KEY_SERVER_PORT = +
+
+

+ This constant is part of a private API. + You should avoid using this constant if possible, as it may be removed or be changed in the future. +

+ +

the key for the server port

+ + +
+
+
+ + +
+
+
'SERVER_PORT'
+
+ +
KEY_SERVER_PROTOCOL = +
+
+

+ This constant is part of a private API. + You should avoid using this constant if possible, as it may be removed or be changed in the future. +

+ +

the key for the server protocol

+ + +
+
+
+ + +
+
+
'SERVER_PROTOCOL'
+
+ +
KEY_SERVER_SOFTWARE = +
+
+

+ This constant is part of a private API. + You should avoid using this constant if possible, as it may be removed or be changed in the future. +

+ +

the key for the server software

+ + +
+
+
+ + +
+
+
'SERVER_SOFTWARE'
+
+ +
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Server) initialize(environment) + + + + + +

+
+ +

This creates a new server instance extracting all server related

+ +
information from the environment.
+ + +
+
+
+ + +
+ + + + +
+
+
+
+20
+21
+22
+23
+24
+25
+
+
# File 'lib/zero/request/server.rb', line 20
+
+def initialize(environment)
+  @hostname = environment[KEY_SERVER_NAME]
+  @port     = environment[KEY_SERVER_PORT].to_i
+  @protocol = environment[KEY_SERVER_PROTOCOL]
+  @software = environment[KEY_SERVER_SOFTWARE]
+end
+
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (String) hostname (readonly) + + + + + +

+
+ +

get the hostname of the server

+ + +
+
+
+ +

Returns:

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

    the hostname

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+32
+33
+34
+
+
# File 'lib/zero/request/server.rb', line 32
+
+def hostname
+  @hostname
+end
+
+
+
+ + + +
+

+ + - (Numeric) port (readonly) + + + + + +

+
+ +

get the port

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Numeric) + + + + — +
    +

    the port

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+29
+30
+31
+
+
# File 'lib/zero/request/server.rb', line 29
+
+def port
+  @port
+end
+
+
+
+ + + +
+

+ + - (String) protocol (readonly) + + + + + +

+
+ +

get the protocol of the server (normally it should be HTTP/1.1)

+ + +
+
+
+ +

Returns:

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

    the protocol

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+35
+36
+37
+
+
# File 'lib/zero/request/server.rb', line 35
+
+def protocol
+  @protocol
+end
+
+
+
+ + + +
+

+ + - (String) software (readonly) + + + + + +

+
+ +

get the server software

+ + +
+
+
+ +

Returns:

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

    the server software name

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+38
+39
+40
+
+
# File 'lib/zero/request/server.rb', line 38
+
+def software
+  @software
+end
+
+
+
+ +
+ + +
+ + + + + \ No newline at end of file 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 diff --git a/doc/Zero/Router.html b/doc/Zero/Router.html new file mode 100644 index 0000000..8f95463 --- /dev/null +++ b/doc/Zero/Router.html @@ -0,0 +1,333 @@ + + + + + + Class: Zero::Router + + — Documentation by YARD 0.8.3 + + + + + + + + + + + + + + + + + + + + + +

Class: Zero::Router + + + +

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

Constant Summary

+ +
+ +
VARIABLE_MATCH = +
+
+ +

match for variables in routes

+ + +
+
+
+ + +
+
+
%r{:(\w+)[^/]?}
+
+ +
VARIABLE_REGEX = +
+
+ +

the replacement string to make it an regex

+ + +
+
+
+ + +
+
+
'(?<\1>.+?)'
+
+ +
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Router) initialize(routes) + + + + + +

+
+ +

A new instance of Router

+ + +
+
+
+ + +
+ + + + +
+
+
+
+8
+9
+10
+11
+12
+13
+14
+15
+
+
# File 'lib/zero/router.rb', line 8
+
+def initialize(routes)
+  @routes = {}
+  routes.each do |route, target|
+    @routes[
+      Regexp.new(
+        route.gsub(VARIABLE_MATCH, VARIABLE_REGEX) + '$')] = target
+  end
+end
+
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) call(env) + + + + + +

+ + + + +
+
+
+
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+
+
# File 'lib/zero/router.rb', line 17
+
+def call(env)
+  request = Zero::Request.create(env)
+  @routes.each do |route, target|
+    match = route.match(request.path)
+    if match
+      match.names.each_index do |i|
+        request.update_param(match.names[i], match.captures[i])
+      end
+      return target.call(request.env)
+    end
+  end
+  [404, {'Content-Type' => 'text/html'}, ['Not found!']]
+end
+
+
+
+ +
+ +
+ + + + + \ No newline at end of file -- cgit v1.2.3-70-g09d2