Browse files

Extract method refactoring for Rails::Server#start

  • Loading branch information...
1 parent f8e5022 commit 919fafa54b7cc9c870b0138c4ec4cfd42edbace1 @notalex notalex committed Nov 7, 2013
Showing with 38 additions and 24 deletions.
  1. +38 −24 railties/lib/rails/commands/server.rb
View
62 railties/lib/rails/commands/server.rb
@@ -61,30 +61,10 @@ def set_environment
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
- 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
+ print_boot_information
+ trap_interrupt_and_print_interrupt_information
+ create_tmp_directories
+ log_to_stdout if options[:log_stdout]
super
ensure
@@ -124,5 +104,39 @@ def default_options
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
+ end
+
+ def trap_interrupt_and_print_interrupt_information
+ trap(:INT) { exit }
+ 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

0 comments on commit 919fafa

Please sign in to comment.