Class ScaffoldingExtensions::RackController

  1. lib/scaffolding_extensions/controller/rack.rb
Parent: Object

Methods

public class

  1. call
  2. scaffold_setup_helper

public instance

  1. call

External Aliases

escape -> u
escape_html -> h

Attributes

params [R]
request [R]
response [R]

Public class methods

call (env)
[show source]
    # File lib/scaffolding_extensions/controller/rack.rb, line 29
29:     def self.call(env)
30:       new.call(env)
31:     end
scaffold_setup_helper ()
[show source]
    # File lib/scaffolding_extensions/controller/rack.rb, line 26
26:     def self.scaffold_setup_helper
27:     end

Public instance methods

call (env)
[show source]
    # File lib/scaffolding_extensions/controller/rack.rb, line 37
37:     def call(env)
38:       s = 200
39:       h = {'Content-Type'=>'text/html'}
40:       b = ''
41:       @params = Hash.new{|hash, k| hash[k.to_s] if k.is_a?(Symbol)}
42:       params.merge!(parse_nested_query(env["QUERY_STRING"]))
43:       params.merge!(parse_nested_query(env["rack.input"].read)) if env["REQUEST_METHOD"] == 'POST'
44: 
45:       @scaffold_method = meth = if ['', '/'].include?(env["PATH_INFO"])
46:         'index'
47:       elsif captures = %r{\A/(\w+)(?:/(\w+))?\z}.match(env["PATH_INFO"])
48:         params['id'] ||= captures[2]
49:         captures[1]
50:       end
51: 
52:       if !['GET', 'POST'].include?(env["REQUEST_METHOD"]) || (env["REQUEST_METHOD"] == "GET" && scaffolded_nonidempotent_method?(meth)) 
53:         return [403, h, 'Method Not Allowed']
54:       end
55: 
56:       if scaffolded_method?(meth)
57:         @scaffold_path = env['SCRIPT_NAME']
58:         @request = env
59:         @response = h
60:         begin
61:           b = send(meth)
62:         rescue Redirect => e
63:           s = 302
64:           h['Location'] = e.message 
65:         end
66:       else
67:         s = 404
68:         b = 'Not Found'
69:       end
70: 
71:       [s, h, [b]]
72:     end