Class: Padrino::Server

Inherits:
Rack::Server
  • Object
show all
Defined in:
lib/padrino-core/server.rb

Overview

This module builds a Padrino server to run the project based on available handlers.

Constant Summary collapse

DEFAULT_ADDRESS =
{ :Host => '127.0.0.1', :Port => 3000 }
Handlers =

Server Handlers

[:thin, :puma, :'spider-gazelle', :mongrel, :trinidad, :webrick]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, app) ⇒ Server

Returns a new instance of Server.



52
53
54
# File 'lib/padrino-core/server.rb', line 52

def initialize(options, app)
  @options, @app = options, app
end

Class Method Details

.start(app, options = {}) ⇒ Object

Starts the application on the available server with specified options.



41
42
43
44
45
46
47
48
49
50
# File 'lib/padrino-core/server.rb', line 41

def self.start(app, options={})
  options = Utils.symbolize_keys(options.to_hash)
  options.update(parse_server_options(options.delete(:options)))
  options.update(detect_address(options))
  options[:pid] = prepare_pid(options[:pid]) if options[:daemonize]
  options[:server] ||= detect_rack_handler
  # disable Webrick AccessLog
  options[:AccessLog] = []
  new(options, app).start
end

Instance Method Details

#appObject Also known as: wrapped_app

The application the server will run.



68
69
70
# File 'lib/padrino-core/server.rb', line 68

def app
  @app
end

#optionsObject



73
74
75
# File 'lib/padrino-core/server.rb', line 73

def options
  @options
end

#startObject

Starts the application on the available server with specified options.



57
58
59
60
61
62
63
64
65
# File 'lib/padrino-core/server.rb', line 57

def start
  puts "=> Padrino/#{Padrino.version} has taken the stage #{Padrino.env} at http://#{options[:Host]}:#{options[:Port]}"
  [:INT, :TERM].each { |sig| trap(sig) { exit } }
  super do |server|
    server.threaded = true if server.respond_to?(:threaded=)
  end
ensure
  puts "<= Padrino leaves the gun, takes the cannoli" unless options[:daemonize]
end