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/Router.html | 333 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 333 insertions(+) create mode 100644 doc/Zero/Router.html (limited to 'doc/Zero/Router.html') 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