Class: Mongrel::Rails::RailsConfigurator
- Inherits:
-
Configurator
- Object
- Configurator
- Mongrel::Rails::RailsConfigurator
- Defined in:
- lib/mongrel/rails.rb
Overview
Creates Rails specific configuration options for people to use instead of the base Configurator.
Instance Attribute Summary
Attributes inherited from Configurator
#defaults, #listeners, #needs_restart
Instance Method Summary collapse
-
#rails(options = {}) ⇒ Object
Creates a single rails handler and returns it so you can add it to a uri.
-
#reload! ⇒ Object
Reloads rails.
-
#setup_rails_signals(options = {}) ⇒ Object
Takes the exact same configuration as Mongrel::Configurator (and actually calls that) but sets up the additional HUP handler to call reload!.
Methods inherited from Configurator
#cloaker, #daemonize, #debug, #initialize, #join, #listener, #load_mime_map, #load_plugins, #load_yaml, #log, #plugin, #resolve_defaults, #run, #setup_signals, #stop, #uri
Constructor Details
This class inherits a constructor from Mongrel::Configurator
Instance Method Details
#rails(options = {}) ⇒ Object
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 (and mulitple) you want, but still protects you from threads destroying your handler.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/mongrel/rails.rb', line 121 def rails(={}) return @rails_handler if @rails_handler ops = resolve_defaults() # fix up some defaults ops[:environment] ||= "development" ops[:docroot] ||= "public" ops[:mime] ||= {} $orig_dollar_quote = $".clone ENV['RAILS_ENV'] = ops[:environment] require "#{ops[:cwd]}/config/environment" require 'dispatcher' require 'mongrel/rails' @rails_handler = RailsHandler.new(ops[:docroot], ops[:mime]) end |
#reload! ⇒ Object
Reloads rails. This isn’t too reliable really, but should work for most minimal reload purposes. Only reliable way it so stop then start the process.
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/mongrel/rails.rb', line 146 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 = {}) ⇒ Object
Takes the exact same configuration as Mongrel::Configurator (and actually calls that) but sets up the additional HUP handler to call reload!.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/mongrel/rails.rb', line 159 def setup_rails_signals(={}) ops = resolve_defaults() if RUBY_PLATFORM !~ /mswin/ setup_signals() # rails reload trap("HUP") { log "HUP signal received." reload! } log "Rails signals registered. HUP => reload (without restart). It might not work well." else log "WARNING: Rails does not support signals on Win32." end end |