Class: ScaffoldingExtensions::RackController

Inherits:
Object
  • Object
show all
Extended by:
MetaController
Includes:
Rack::Utils, Controller, Helper
Defined in:
lib/scaffolding_extensions/controller/rack.rb

Defined Under Namespace

Classes: Redirect

Instance Attribute Summary collapse

Attributes included from MetaController

#scaffolded_auto_complete_associations, #scaffolded_methods, #scaffolded_nonidempotent_methods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MetaController

scaffold_default_action, scaffold_template_dir

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



35
36
37
# File 'lib/scaffolding_extensions/controller/rack.rb', line 35

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



33
34
35
# File 'lib/scaffolding_extensions/controller/rack.rb', line 33

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



34
35
36
# File 'lib/scaffolding_extensions/controller/rack.rb', line 34

def response
  @response
end

Class Method Details

.call(env) ⇒ Object



29
30
31
# File 'lib/scaffolding_extensions/controller/rack.rb', line 29

def self.call(env)
  new.call(env)
end

.scaffold_setup_helperObject



26
27
# File 'lib/scaffolding_extensions/controller/rack.rb', line 26

def self.scaffold_setup_helper
end

Instance Method Details

#call(env) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/scaffolding_extensions/controller/rack.rb', line 37

def call(env)
  s = 200
  h = {'Content-Type'=>'text/html'}
  b = ''
  @params = Hash.new{|hash, k| hash[k.to_s] if k.is_a?(Symbol)}
  params.merge!(parse_nested_query(env["QUERY_STRING"]))
  params.merge!(parse_nested_query(env["rack.input"].read)) if env["REQUEST_METHOD"] == 'POST'

  @scaffold_method = meth = if ['', '/'].include?(env["PATH_INFO"])
    'index'
  elsif captures = %r{\A/(\w+)(?:/(\w+))?\z}.match(env["PATH_INFO"])
    params['id'] ||= captures[2]
    captures[1]
  end

  if !['GET', 'POST'].include?(env["REQUEST_METHOD"]) || (env["REQUEST_METHOD"] == "GET" && scaffolded_nonidempotent_method?(meth)) 
    return [403, h, 'Method Not Allowed']
  end

  if scaffolded_method?(meth)
    @scaffold_path = env['SCRIPT_NAME']
    @request = env
    @response = h
    begin
      b = send(meth)
    rescue Redirect => e
      s = 302
      h['Location'] = e.message 
    end
  else
    s = 404
    b = 'Not Found'
  end

  [s, h, [b]]
end