123456789_123456789_123456789_123456789_123456789_

Class: Rails::Server

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Rackup::Server
Instance Chain:
self, Rackup::Server
Inherits: Rackup::Server
Defined in: railties/lib/rails/commands/server/server_command.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(options = nil) ⇒ Server

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 18

def initialize(options = nil)
  @default_options = options || {}
  super(@default_options)
  set_environment
end

Instance Attribute Details

#serveable?Boolean (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 43

def serveable? # :nodoc:
  server
  true
rescue LoadError, NameError
  false
end

#use_puma?Boolean (readonly, private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 87

def use_puma?
  server.to_s.end_with?("Handler::Puma")
end

Instance Method Details

#create_tmp_directories (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 69

def create_tmp_directories
  %w(cache pids sockets).each do |dir_to_make|
    FileUtils.mkdir_p(File.join(Rails.root, "tmp", dir_to_make))
  end
end

#default_options

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 54

def default_options
  super.merge(@default_options)
end

#log_to_stdout (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 75

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

  unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDERR, STDOUT)
    Rails.logger.broadcast_to(console)
  end
end

#middleware

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 50

def middleware
  Hash.new([])
end

#opt_parser

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 24

def opt_parser
  Options.new
end

#served_url

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 58

def served_url
  "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}" unless use_puma?
end

#set_environment

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 28

def set_environment
  ENV["RAILS_ENV"] ||= options[:environment]
end

#setup_dev_caching (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 63

def setup_dev_caching
  if options[:environment] == "development"
    Rails::DevCaching.enable_by_argument(options[:caching])
  end
end

#start(after_stop_callback = nil)

[ GitHub ]

  
# File 'railties/lib/rails/commands/server/server_command.rb', line 32

def start(after_stop_callback = nil)
  trap(:INT) { exit }
  create_tmp_directories
  setup_dev_caching
  log_to_stdout if options[:log_stdout]

  super()
ensure
  after_stop_callback.call if after_stop_callback
end