Class: Mongrel::Rails::RailsConfigurator

### Home Classes Methods

### In Files

- lib/mongrel/rails.rb

### Parent

Mongrel::Configurator

### Methods

- #rails
- #reload!
- #setup_rails_signals

### Files

- CHANGELOG
- COPYING
- LICENSE
- README
- Makefile

### Class/Module Index

Quicksearch

- Mongrel
- Mongrel::CGIWrapper
- Mongrel::Camping
- Mongrel::Camping::CampingHandler
- Mongrel::Command
- Mongrel::Command::Base
- Mongrel::Command::Registry
- Mongrel::Configurator
- Mongrel::Const
- Mongrel::DeflateFilter
- Mongrel::DirHandler
- Mongrel::Error404Handler
- Mongrel::Gems
- Mongrel::HeaderOut
- Mongrel::HttpHandler
- Mongrel::HttpHandlerPlugin
- Mongrel::HttpParams
- Mongrel::HttpParser
- Mongrel::HttpParserError
- Mongrel::HttpRequest
- Mongrel::HttpResponse
- Mongrel::HttpServer
- Mongrel::Rails
- Mongrel::Rails::RailsConfigurator
- Mongrel::Rails::RailsHandler
- Mongrel::RedirectHandler
- Mongrel::StatisticsFilter
- Mongrel::Stats
- Mongrel::StatusHandler
- Mongrel::StopServer
- Mongrel::TimeoutError
- Mongrel::URIClassifier
- Mongrel::URIClassifier::RegistrationError
- Mongrel::URIClassifier::UsageError
- RequestLog
- RequestLog::Access
- RequestLog::Files
- RequestLog::Objects
- RequestLog::Params
- RequestLog::Threads
- IO
- Kernel
- MongrelDbg
- TCPServer

No matching classes.

# Mongrel::Rails::RailsConfigurator

Creates Rails specific configuration options for people to use instead of the base Configurator.

### Public Instance Methods

rails(options={}) click to toggle source

Creates a single rails handler and returns it so you can add it to a URI. You can actually attach it to as many URIs as you want, but this returns the same RailsHandler for each call.

Requires the following options:

- :docroot => The public dir to serve from.

- :environment => Rails environment to use.

- :cwd => The change to working directory

And understands the following optional settings:

- :mime => A map of mime types.

Because of how Rails is designed you can only have one installed per Ruby interpreter (talk to them about thread safety). Because of this the first time you call this function it does all the config needed to get your Rails working. After that it returns the one handler you've configured. This lets you attach Rails to any URI(s) you want, but it still protects you from threads destroying your handler.

    # File lib/mongrel/rails.rb, line 133
    def rails(options={})

      return @rails_handler if @rails_handler

      ops = resolve_defaults(options)

      # fix up some defaults
      ops[:environment] ||= "development"
      ops[:docroot] ||= "public"
      ops[:mime] ||= {}

      $orig_dollar_quote = $".clone
      ENV['RAILS_ENV'] = ops[:environment]
      env_location = "#{ops[:cwd]}/config/environment"
      require env_location
      require 'dispatcher'
      require 'mongrel/rails'

      ActionController::AbstractRequest.relative_url_root = ops[:prefix] if ops[:prefix]

      @rails_handler = RailsHandler.new(ops[:docroot], ops[:mime])
    end

reload!() click to toggle source

Reloads Rails. This isn't too reliable really, but it should work for most minimal reload purposes. The only reliable way to reload properly is to stop and then start the process.

    # File lib/mongrel/rails.rb, line 159
    def reload!
      if not @rails_handler
        raise "Rails was not configured.  Read the docs for RailsConfigurator."
      end

      log "Reloading Rails..."
      @rails_handler.reload!
      log "Done reloading Rails."

    end

setup_rails_signals(options={}) click to toggle source

Takes the exact same configuration as Mongrel::Configurator (and actually calls that) but sets up the additional HUP handler to call reload!.

    # File lib/mongrel/rails.rb, line 172
    def setup_rails_signals(options={})
      ops = resolve_defaults(options)
      setup_signals(options)

      if RUBY_PLATFORM !~ /mswin/
        # rails reload
        trap("HUP") { log "HUP signal received."; reload!          }

        log "Rails signals registered.  HUP => reload (without restart).  It might not work well."
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.