Class: Thin::RailsHandler

Inherits:
Handler
  • Object
show all
Defined in:
lib/thin/rails.rb

Overview

Forwards incoming request to Rails dispatcher.

Instance Method Summary collapse

Constructor Details

#initialize(pwd, env = 'development') ⇒ RailsHandler

Returns a new instance of RailsHandler.



4
5
6
7
# File 'lib/thin/rails.rb', line 4

def initialize(pwd, env='development')
  @env = env
  @pwd = pwd
end

Instance Method Details

#process(request, response) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/thin/rails.rb', line 16

def process(request, response)
  # Rails doesn't serve static files
  # TODO handle Rails page caching
  return false if File.file?(File.join(@pwd, 'public', request.path))
  
  cgi = CGIWrapper.new(request, response)
  
  Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
  
  # This finalizes the output using the proper HttpResponse way
  cgi.out("text/html", true) {""}
end

#startObject



9
10
11
12
13
14
# File 'lib/thin/rails.rb', line 9

def start
  ENV['RAILS_ENV'] = @env
  
  require "#{@pwd}/config/environment"
  require 'dispatcher'
end

#to_sObject



29
30
31
# File 'lib/thin/rails.rb', line 29

def to_s
  "Rails on #{@pwd} (env=#{@env})"
end