Class: Mongrel::Rails::RailsConfigurator

Class | Mongrel::Rails::RailsConfigurator
In: | lib/mongrel/rails.rb lib/mongrel/rails.rb
Parent: | Mongrel::Configurator

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

### Methods

rails rails reload! reload! setup_rails_signals setup_rails_signals

### Public Instance methods

rails(options={})

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.

[Source]

         # File lib/mongrel/rails.rb, line 133
    133:       def rails(options={})
    134:
    135:         return @rails_handler if @rails_handler
    136:
    137:         ops = resolve_defaults(options)
    138:
    139:         # fix up some defaults
    140:         ops[:environment] ||= "development"
    141:         ops[:docroot] ||= "public"
    142:         ops[:mime] ||= {}
    143:
    144:         $orig_dollar_quote = $".clone
    145:         ENV['RAILS_ENV'] = ops[:environment]
    146:         env_location = "#{ops[:cwd]}/config/environment"
    147:         require env_location
    148:         require 'dispatcher'
    149:         require 'mongrel/rails'
    150:
    151:         ActionController::AbstractRequest.relative_url_root = ops[:prefix] if ops[:prefix]
    152:
    153:         @rails_handler = RailsHandler.new(ops[:docroot], ops[:mime])
    154:       end

rails(options={})

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.

[Source]

         # File lib/mongrel/rails.rb, line 133
    133:       def rails(options={})
    134:
    135:         return @rails_handler if @rails_handler
    136:
    137:         ops = resolve_defaults(options)
    138:
    139:         # fix up some defaults
    140:         ops[:environment] ||= "development"
    141:         ops[:docroot] ||= "public"
    142:         ops[:mime] ||= {}
    143:
    144:         $orig_dollar_quote = $".clone
    145:         ENV['RAILS_ENV'] = ops[:environment]
    146:         env_location = "#{ops[:cwd]}/config/environment"
    147:         require env_location
    148:         require 'dispatcher'
    149:         require 'mongrel/rails'
    150:
    151:         ActionController::AbstractRequest.relative_url_root = ops[:prefix] if ops[:prefix]
    152:
    153:         @rails_handler = RailsHandler.new(ops[:docroot], ops[:mime])
    154:       end

reload!()

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.

[Source]

         # File lib/mongrel/rails.rb, line 159
    159:       def reload!
    160:         if not @rails_handler
    161:           raise "Rails was not configured.  Read the docs for RailsConfigurator."
    162:         end
    163:
    164:         log "Reloading Rails..."
    165:         @rails_handler.reload!
    166:         log "Done reloading Rails."
    167:
    168:       end

reload!()

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.

[Source]

         # File lib/mongrel/rails.rb, line 159
    159:       def reload!
    160:         if not @rails_handler
    161:           raise "Rails was not configured.  Read the docs for RailsConfigurator."
    162:         end
    163:
    164:         log "Reloading Rails..."
    165:         @rails_handler.reload!
    166:         log "Done reloading Rails."
    167:
    168:       end

setup_rails_signals(options={})

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

[Source]

         # File lib/mongrel/rails.rb, line 172
    172:       def setup_rails_signals(options={})
    173:         ops = resolve_defaults(options)
    174:         setup_signals(options)
    175:
    176:         if RUBY_PLATFORM !~ /mswin/
    177:           # rails reload
    178:           trap("HUP") { log "HUP signal received."; reload!          }
    179:
    180:           log "Rails signals registered.  HUP => reload (without restart).  It might not work well."
    181:         end
    182:       end

setup_rails_signals(options={})

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

[Source]

         # File lib/mongrel/rails.rb, line 172
    172:       def setup_rails_signals(options={})
    173:         ops = resolve_defaults(options)
    174:         setup_signals(options)
    175:
    176:         if RUBY_PLATFORM !~ /mswin/
    177:           # rails reload
    178:           trap("HUP") { log "HUP signal received."; reload!          }
    179:
    180:           log "Rails signals registered.  HUP => reload (without restart).  It might not work well."
    181:         end
    182:       end

[Validate]