From 18eb7ba4d2444c002cf4f4cb5baac4eed12039b8 Mon Sep 17 00:00:00 2001 From: David Waite Date: Fri, 1 Jul 2011 00:25:52 -0600 Subject: [PATCH 1/2] Delay sinatra message until handler has started; Application.run! has optional block to execute once handler is going --- lib/sinatra/base.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 48c0556a..8ae64668 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -1188,16 +1188,20 @@ module Sinatra end # Run the Sinatra app as a self-hosted server using - # Thin, Mongrel or WEBrick (in that order) + # Thin, Mongrel or WEBrick (in that order). If given a block, will call + # with the constructed handler once we have taken the stage. def run!(options={}) set options handler = detect_rack_handler handler_name = handler.name.gsub(/.*::/, '') - $stderr.puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " + - "on #{port} for #{environment} with backup from #{handler_name}" unless handler_name =~/cgi/i handler.run self, :Host => bind, :Port => port do |server| + unless handler_name =~ /cgi/i + $stderr.puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " + + "on #{port} for #{environment} with backup from #{handler_name}" + end [:INT, :TERM].each { |sig| trap(sig) { quit!(server, handler_name) } } set :running, true + yield handler if block_given? end rescue Errno::EADDRINUSE => e $stderr.puts "== Someone is already performing on port #{port}!" From fd18d026048771d6ebe44a51b69614dffe7f7e48 Mon Sep 17 00:00:00 2001 From: Gabriel Andretta Date: Fri, 1 Jul 2011 20:55:08 -0300 Subject: [PATCH 2/2] point out that the example is a config.ru in the other readmes --- README.de.rdoc | 1 + README.es.rdoc | 1 + README.fr.rdoc | 1 + README.ru.rdoc | 1 + 4 files changed, 4 insertions(+) diff --git a/README.de.rdoc b/README.de.rdoc index 92f1df12..d33f088b 100644 --- a/README.de.rdoc +++ b/README.de.rdoc @@ -1520,6 +1520,7 @@ ohne dass sie einer Konstanten zugeordnet werden. Dies lässt sich mit Die Applikation kann mit Hilfe eines optionalen Parameters erstellt werden: + # config.ru require 'sinatra/base' controller = Sinatra.new do diff --git a/README.es.rdoc b/README.es.rdoc index 91a56906..0825d948 100644 --- a/README.es.rdoc +++ b/README.es.rdoc @@ -1581,6 +1581,7 @@ esto tenés Sinatra.new: Acepta como argumento opcional una aplicación desde la que se heredará: + # config.ru require 'sinatra/base' controller = Sinatra.new do diff --git a/README.fr.rdoc b/README.fr.rdoc index f6f0331f..ce430d36 100644 --- a/README.fr.rdoc +++ b/README.fr.rdoc @@ -1585,6 +1585,7 @@ sans avoir à les assigner à une constante, vous pouvez le faire grâce à L'application dont elle hérite peut être passé en argument optionnel : + # config.ru require 'sinatra/base' controleur = Sinatra.new do diff --git a/README.ru.rdoc b/README.ru.rdoc index 9a165a41..fd2d2f0b 100644 --- a/README.ru.rdoc +++ b/README.ru.rdoc @@ -1519,6 +1519,7 @@ Rack-совместимый сервер приложений. Этот метод может принимать аргументом приложение, от которого следует наследоваться: + # config.ru require 'sinatra/base' controller = Sinatra.new do