Parent

Class Index [+]

Quicksearch

Ferret::Browser::Delegator

Public Class Methods

new(reader, path) click to toggle source
   # File lib/ferret/browser.rb, line 6
6:     def initialize(reader, path)
7:       @reader, @path = reader, path
8:     end

Public Instance Methods

run(env) click to toggle source
    # File lib/ferret/browser.rb, line 10
10:     def run(env)
11:       controller, action, args = :home, :index, nil
12:       query_string = env['QUERY_STRING']||''
13:       params = parse_query_string(query_string)
14:       req_path = env['PATH_INFO'].gsub(/\/+/, '/')
15:       case req_path
16:       when '/'
17:         # nothing to do
18:       when /^\/?([-a-zA-Z]+)\/?$/
19:         controller = $1
20:       when /^\/?([-a-zA-Z]+)\/([-a-zA-Z]+)\/?(.*)?$/
21:         controller = $1
22:         action = $2
23:         args = $3
24:       else
25:         controller = :error
26:         args = req_path
27:       end
28:       controller_vars = {
29:         :params => params,
30:         :req_path => req_path,
31:         :query_string => query_string,
32:       }
33:       delegate(controller, action, args, controller_vars)
34:     end

Private Instance Methods

delegate(controller, action, args, controller_vars) click to toggle source
    # File lib/ferret/browser.rb, line 38
38:     def delegate(controller, action, args, controller_vars)
39:       begin
40:         controller = to_const(controller, 'Controller').
41:           new(@reader, @path, controller_vars)
42:         controller.send(action, args)
43:       rescue Exception => e
44:         puts e.to_s
45:         controller_vars[:params][:error] = e
46:         ErrorController.new(@reader, @path, controller_vars).index
47:       end
48:     end
parse_query_string(query_string, delim = '&;') click to toggle source
    # File lib/ferret/browser.rb, line 60
60:     def parse_query_string(query_string, delim = '&;')
61:       m = proc {|_,o,n| o.update(n, &m) rescue ([*o] << n)}
62:       (query_string||'').split(/[#{delim}] */).
63:         inject({}) { |hash, param| key, val = unescape_uri(param).split('=',2)
64:           hash.update(key.split(/[\]\[]+/).reverse.
65:             inject(val) { |x,i| Hash[i,x] }, &m)
66:         } 
67:     end
to_const(str, suffix='') click to toggle source
    # File lib/ferret/browser.rb, line 50
50:     def to_const(str, suffix='')
51:       Ferret::Browser.const_get(str.to_s.split('-').
52:                                 map {|w| w.capitalize}.join('') + suffix)
53:     end
unescape_uri(s) click to toggle source

from _why’s camping

    # File lib/ferret/browser.rb, line 56
56:     def unescape_uri(s)
57:       s.tr('+', ' ').gsub(/%([\da-f]{2})/n){[$1].pack('H*')}
58:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.