diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-07 05:58:09 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-07 05:58:09 -0800 |
commit | 99da3fc098306174f53186cd0c7c5dd45c1382dd (patch) | |
tree | 78b1897c755e418f75822a8e6f701b052b8117c3 /railties/lib | |
parent | 1dfe05f98eaa0b8067fa1dfd019d44c851879b22 (diff) | |
parent | 1410d46b30526f3e4fd1148fe5fb19f83550aab2 (diff) | |
download | rails-99da3fc098306174f53186cd0c7c5dd45c1382dd.tar.gz rails-99da3fc098306174f53186cd0c7c5dd45c1382dd.tar.bz2 rails-99da3fc098306174f53186cd0c7c5dd45c1382dd.zip |
Merge pull request #12787 from notalex/extract_method
Extract method refactoring for Rails::Server#start
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands/server.rb | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 4201dac42f..1e90c57fb4 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -61,30 +61,10 @@ module Rails end def start - url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}" - puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" - puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}" - puts "=> Run `rails server -h` for more startup options" - if options[:Host].to_s.match(/0\.0\.0\.0/) - puts "=> Notice: server is listening on all interfaces (#{options[:Host]}). Consider using 127.0.0.1 (--binding option)" - end + print_boot_information trap(:INT) { exit } - puts "=> Ctrl-C to shutdown server" unless options[:daemonize] - - #Create required tmp directories if not found - %w(cache pids sessions sockets).each do |dir_to_make| - FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make)) - end - - if options[:log_stdout] - wrapped_app # touch the app so the logger is set up - - console = ActiveSupport::Logger.new($stdout) - console.formatter = Rails.logger.formatter - console.level = Rails.logger.level - - Rails.logger.extend(ActiveSupport::Logger.broadcast(console)) - end + create_tmp_directories + log_to_stdout if options[:log_stdout] super ensure @@ -124,5 +104,36 @@ module Rails config: File.expand_path("config.ru") }) end + + private + + def print_boot_information + url = "#{ options[:SSLEnable] ? 'https' : 'http' }://#{ options[:Host] }:#{ options[:Port] }" + puts "=> Booting #{ ActiveSupport::Inflector.demodulize(server) }" + puts "=> Rails #{ Rails.version } application starting in #{ Rails.env } on #{ url }" + puts "=> Run `rails server -h` for more startup options" + + if options[:Host].to_s.match(/0\.0\.0\.0/) + puts "=> Notice: server is listening on all interfaces (#{ options[:Host] }). Consider using 127.0.0.1 (--binding option)" + end + + puts "=> Ctrl-C to shutdown server" unless options[:daemonize] + end + + def create_tmp_directories + %w(cache pids sessions sockets).each do |dir_to_make| + FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make)) + end + end + + def log_to_stdout + wrapped_app # touch the app so the logger is set up + + console = ActiveSupport::Logger.new($stdout) + console.formatter = Rails.logger.formatter + console.level = Rails.logger.level + + Rails.logger.extend(ActiveSupport::Logger.broadcast(console)) + end end end |