Class: Wunderbar::RackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/wunderbar/rack.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

entry point for Rack



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wunderbar/rack.rb', line 7

def call(env)
  @_env = env
  @_request = Rack::Request.new(env)
  @_response = Rack::Response.new
  Wunderbar.logger = @_request.logger
  file = Wunderbar.files[env['PATH_INFO']]

  if file
    mime = file[:mime] ||
      Rack::Mime::MIME_TYPES[File.extname(env['PATH_INFO'])]
    @_response.set_header('Content-Type', mime) if mime
    @_response.write(file[:content] || file[:source].call)
  elsif Wunderbar.safe? and $SAFE==0
    Proc.new { $SAFE=1; Wunderbar::CGI.call(self) }.call
  else
    Wunderbar::CGI.call(self)
  end
  @_response.finish
end

#envObject



38
39
40
# File 'lib/wunderbar/rack.rb', line 38

def env
  @_env
end

#out(headers, &block) ⇒ Object

redirect the output produced



28
29
30
31
32
33
34
35
36
# File 'lib/wunderbar/rack.rb', line 28

def out(headers,&block)
  status = headers.delete('status')
  @_response.status = status if status

  headers = Wunderbar::CGI.headers(headers)
  headers.each {|key, value| @_response[key] = value}

  @_response.write block.call unless @_request.head?
end

#paramsObject



42
43
44
# File 'lib/wunderbar/rack.rb', line 42

def params
  @_request.params
end

#requestObject



46
47
48
# File 'lib/wunderbar/rack.rb', line 46

def request
  @_request
end

#responseObject



50
51
52
# File 'lib/wunderbar/rack.rb', line 50

def response
  @_response
end