definitialize!(group=:default)#:nodoc:raise"Application has been already initialized."if@initializedrun_initializers(group,self)@initialized=trueselfend
defapp@app||=beginif!::File.exist?options[:config]abort"configuration #{options[:config]} not found"endapp,options=Rack::Builder.parse_file(self.options[:config],opt_parser)self.options.merge!optionsappendend
defself.run(app,options={})server=::Mongrel::HttpServer.new(options[:Host]||'0.0.0.0',options[:Port]||8080,options[:num_processors]||950,options[:throttle]||0,options[:timeout]||60)# Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.# Use is similar to #run, replacing the app argument with a hash of# { path=>app, ... } or an instance of Rack::URLMap.ifoptions[:map]ifapp.is_a?Hashapp.eachdo|path,appl|path='/'+pathunlesspath[0]==?/server.register(path,Rack::Handler::Mongrel.new(appl))endelsifapp.is_a?URLMapapp.instance_variable_get(:@mapping).eachdo|(host,path,appl)|nextif!host.nil?&&!options[:Host].nil?&&options[:Host]!=hostpath='/'+pathunlesspath[0]==?/server.register(path,Rack::Handler::Mongrel.new(appl))endelseraiseArgumentError,"first argument should be a Hash or URLMap"endelseserver.register('/',Rack::Handler::Mongrel.new(app))endyieldserverifblock_given?server.run.joinend