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



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

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)
  else
    Wunderbar::CGI.call(self)
  end
  @_response.finish
end

#envObject



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

def env
  @_env
end

#out(headers, &block) ⇒ Object

redirect the output produced



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

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



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

def params
  @_request.params
end

#requestObject



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

def request
  @_request
end

#responseObject



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

def response
  @_response
end