Class: Rack::Adapter::Rails

### Home Classes Methods

### In Files

- lib/rack/adapter/rails.rb

### Parent

Object

### Namespace

- CLASS Rack::Adapter::Rails::CGIWrapper
- CLASS Rack::Adapter::Rails::CgiApp

### Methods

- ::new
- ::rack_based?
- #call
- #file_exist?
- #load_application

### Class/Module Index

Quicksearch

- Thin
- Thin::Backends
- Thin::Backends::Base
- Thin::Backends::SwiftiplyClient
- Thin::Backends::TcpServer
- Thin::Backends::UnixServer
- Thin::Command
- Thin::Connection
- Thin::Controllers
- Thin::Controllers::Cluster
- Thin::Controllers::Controller
- Thin::Controllers::Service
- Thin::Daemonizable
- Thin::Daemonizable::ClassMethods
- Thin::Headers
- Thin::InvalidOption
- Thin::InvalidRequest
- Thin::Logging
- Thin::Logging::SimpleFormatter
- Thin::OptionRequired
- Thin::PidFileExist
- Thin::PidFileNotFound
- Thin::PlatformNotSupported
- Thin::Request
- Thin::Response
- Thin::RestartTimeout
- Thin::Runner
- Thin::RunnerError
- Thin::Server
- Thin::Stats
- Thin::Stats::Adapter
- Thin::SwiftiplyConnection
- Thin::UnixConnection
- Rack
- Rack::Adapter
- Rack::Adapter::Rails
- Rack::Adapter::Rails::CGIWrapper
- Rack::Adapter::Rails::CgiApp
- Rack::AdapterNotFound
- Process

No matching classes.

# Rack::Adapter::Rails

### Constants

FILE_METHODS

### Public Class Methods

new(options = {}) click to toggle source

    # File lib/rack/adapter/rails.rb, line 18
    def initialize(options = {})
      @root   = options[:root]        || Dir.pwd
      @env    = options[:environment] || 'development'
      @prefix = options[:prefix]

      load_application

      @rails_app = self.class.rack_based? ? ActionController::Dispatcher.new : CgiApp.new
      @file_app  = Rack::File.new(::File.join(RAILS_ROOT, "public"))
    end

rack_based?() click to toggle source

    # File lib/rack/adapter/rails.rb, line 67
    def self.rack_based?
      rails_version = ::Rails::VERSION
      return false if rails_version::MAJOR < 2
      return false if rails_version::MAJOR == 2 && rails_version::MINOR < 2
      return false if rails_version::MAJOR == 2 && rails_version::MINOR == 2 && rails_version::TINY < 3
      true # >= 2.2.3
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/rack/adapter/rails.rb, line 49
    def call(env)
      path        = env['PATH_INFO'].chomp('/')
      method      = env['REQUEST_METHOD']
      cached_path = (path.empty? ? 'index' : path) + ActionController::Base.page_cache_extension

      if FILE_METHODS.include?(method)
        if file_exist?(path)              # Serve the file if it's there
          return @file_app.call(env)
        elsif file_exist?(cached_path)    # Serve the page cache if it's there
          env['PATH_INFO'] = cached_path
          return @file_app.call(env)
        end
      end

      # No static file, let Rails handle it
      @rails_app.call(env)
    end

file_exist?(path) click to toggle source

    # File lib/rack/adapter/rails.rb, line 44
    def file_exist?(path)
      full_path = ::File.join(@file_app.root, Utils.unescape(path))
      ::File.file?(full_path) && ::File.readable_real?(full_path)
    end

load_application() click to toggle source

    # File lib/rack/adapter/rails.rb, line 29
    def load_application
      ENV['RAILS_ENV'] = @env

      require "#{@root}/config/environment"
      require 'dispatcher'

      if @prefix
        if ActionController::Base.respond_to?(:relative_url_root=)
          ActionController::Base.relative_url_root = @prefix # Rails 2.1.1
        else
          ActionController::AbstractRequest.relative_url_root = @prefix
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.