Class: Padrino::Server

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

Overview

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

Constant Summary collapse

Handlers =

Server Handlers

[:thin, :puma, :mongrel, :trinidad, :webrick]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, app) ⇒ Server

Returns a new instance of Server.



37
38
39
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/server.rb', line 37

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

Class Method Details

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

Starts the application on the available server with specified options.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/server.rb', line 23

def self.start(app, opts={})
  options = {}.merge(opts) # We use a standard hash instead of Thor::CoreExt::HashWithIndifferentAccess
  options.symbolize_keys!
  options[:Host] = options.delete(:host) || '127.0.0.1' 
  options[:Port] = options.delete(:port) || 3000
  options[:AccessLog] = []
  if options[:daemonize]
    options[:pid] = File.expand_path(options[:pid].blank? ? 'tmp/pids/server.pid' : opts[:pid])
    FileUtils.mkdir_p(File.dirname(options[:pid]))
  end
  options[:server] = detect_rack_handler if options[:server].blank?
  new(options, app).start
end

Instance Method Details

#appObject Also known as: wrapped_app

The application the server will run.



51
52
53
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/server.rb', line 51

def app
  @app
end

#optionsObject

The options specified to the server.



57
58
59
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/server.rb', line 57

def options
  @options
end

#startObject

Starts the application on the available server with specified options.



42
43
44
45
46
47
48
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/server.rb', line 42

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
ensure
  puts "<= Padrino leaves the gun, takes the cannoli" unless options[:daemonize]
end