Dispatcher.to_prepare with script/server and mongrel

I am using the Dispatcher/config.to_prepare hook to configure my application, but mongrel plays a trick with us.

The problem with running this with script/server is this:

1) Dispatcher, at line 160, sets self.preparation_callbacks = 2) Dispatcher gets loaded twice, once by the initalizer, and once by mongrel:

./script/../config/../vendor/rails/railties/lib/initializer.rb:4 /opt/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/mongrel/rails.rb:145:in `rails'

Since the first requires dispatcher with the full path, and the other with just 'dispatcher', the file gets loaded twice (see footnote in pickaxe p117). The second load happens after all environment stuff has been loaded, and wipes our callbacks.

It looks like it works OK in production, it's just when run with script/server.

Two suggestions for fixing, which both work because we're not reloading the Dispatcher between requests:

1) Add an "unless defined? Dispatcher" to the defining of the Dispatcher class, or just to line 160 (which resets the preparation_callbacks array)

2) Change Dispatcher.rb:160 to read "self.preparation_callbacks ||= ", so it's left alone if already defined.

Anything better?

//Lars