Class: Rack::Adapter::Rails
Class Rack::Adapter::Rails < Object
(in files lib/rack/adapter/rails.rb )Adapter to run a Rails app with any supported Rack handler. By default it will try to load the Rails application in the current directory in the development environment.
Options:
root: Root directory of the Rails app environment: Rails environment to run in (development [default], production or test) prefix: Set the relative URL root.
Based on fuzed.rubyforge.org/ Rails adapter
Methods
Public Class new(options={})
[ show source ]
# File lib/rack/adapter/rails.rb, line 18
18: def initialize(options={})
19: @root = options[:root] || Dir.pwd
20: @env = options[:environment] || 'development'
21: @prefix = options[:prefix]
22:
23: load_application
24:
25: @rails_app = if ActionController::Dispatcher.instance_methods.include?(:call)
26: ActionController::Dispatcher.new
27: else
28: CgiApp.new
29: end
30:
31: @file_app = Rack::File.new(::File.join(RAILS_ROOT, "public"))
32: end
Public Instance call(env)
[ show source ]
# File lib/rack/adapter/rails.rb, line 54
54: def call(env)
55: path = env['PATH_INFO'].chomp('/')
56: method = env['REQUEST_METHOD']
57: cached_path = (path.empty? ? 'index' : path) + ActionController::Base.page_cache_extension
58:
59: if FILE_METHODS.include?(method)
60: if file_exist?(path) # Serve the file if it's there
61: return @file_app.call(env)
62: elsif file_exist?(cached_path) # Serve the page cache if it's there
63: env['PATH_INFO'] = cached_path
64: return @file_app.call(env)
65: end
66: end
67:
68: # No static file, let Rails handle it
69: @rails_app.call(env)
70: end
Public Instance file_exist?(path)
[ show source ]
# File lib/rack/adapter/rails.rb, line 49
49: def file_exist?(path)
50: full_path = ::File.join(@file_app.root, Utils.unescape(path))
51: ::File.file?(full_path) && ::File.readable_real?(full_path)
52: end
Public Instance load_application()
[ show source ]
# File lib/rack/adapter/rails.rb, line 34
34: def load_application
35: ENV['RAILS_ENV'] = @env
36:
37: require "#{@root}/config/environment"
38: require 'dispatcher'
39:
40: if @prefix
41: if ActionController::Base.respond_to?(:relative_url_root=)
42: ActionController::Base.relative_url_root = @prefix # Rails 2.1.1
43: else
44: ActionController::AbstractRequest.relative_url_root = @prefix
45: end
46: end
47: end