Class: Padrino::Server
- Defined in:
- padrino-core/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]
Instance Attribute Summary collapse
-
#app ⇒ Object
(also: #wrapped_app)
readonly
The application the server will run.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.detect_address(options) ⇒ Object
Detects Host and Port for Rack server.
-
.detect_rack_handler ⇒ Object
Detects the supported handler to use.
-
.parse_server_options(options) ⇒ Object
Parses an array of server options.
-
.prepare_pid(pid) ⇒ Object
Prepares a directory for pid file.
-
.start(app, options = {}) ⇒ Object
Starts the application on the available server with specified options.
Instance Method Summary collapse
-
#initialize(options, app) ⇒ Server
constructor
A new instance of Server.
-
#start ⇒ Object
Starts the application on the available server with specified options.
Constructor Details
#initialize(options, app) ⇒ Server
Returns a new instance of Server.
51 52 53 |
# File 'padrino-core/lib/padrino-core/server.rb', line 51 def initialize(, app) @options, @app = , app end |
Instance Attribute Details
#app ⇒ Object (readonly) Also known as: wrapped_app
The application the server will run.
67 68 69 |
# File 'padrino-core/lib/padrino-core/server.rb', line 67 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
70 71 72 |
# File 'padrino-core/lib/padrino-core/server.rb', line 70 def @options end |
Class Method Details
.detect_address(options) ⇒ Object
Detects Host and Port for Rack server.
104 105 106 107 108 109 |
# File 'padrino-core/lib/padrino-core/server.rb', line 104 def self.detect_address() address = DEFAULT_ADDRESS.merge(.select{ |key| [:Host, :Port].include?(key) }) address[:Host] = [:host] if [:host] address[:Port] = [:port] if [:port] address end |
.detect_rack_handler ⇒ Object
Detects the supported handler to use.
78 79 80 81 82 83 84 85 |
# File 'padrino-core/lib/padrino-core/server.rb', line 78 def self.detect_rack_handler Handlers.each do |handler| return handler if Rackup::Handler.get(handler.to_s.downcase) rescue LoadError, NameError # Ignored end fail "Server handler (#{Handlers.join(', ')}) not found." end |
.parse_server_options(options) ⇒ Object
Parses an array of server options.
97 98 99 100 |
# File 'padrino-core/lib/padrino-core/server.rb', line 97 def self.() = Array().flat_map{ |option| option.split('=', 2) } Utils.symbolize_keys(Hash[*]) end |
.prepare_pid(pid) ⇒ Object
Prepares a directory for pid file.
89 90 91 92 93 |
# File 'padrino-core/lib/padrino-core/server.rb', line 89 def self.prepare_pid(pid) pid ||= 'tmp/pids/server.pid' FileUtils.mkdir_p(File.dirname(pid)) File.(pid) end |
.start(app, options = {}) ⇒ Object
Starts the application on the available server with specified options.
40 41 42 43 44 45 46 47 48 49 |
# File 'padrino-core/lib/padrino-core/server.rb', line 40 def self.start(app, ={}) = Utils.symbolize_keys(.to_hash) .update((.delete(:options))) .update(detect_address()) [:pid] = prepare_pid([:pid]) if [:daemonize] [:server] ||= detect_rack_handler # disable Webrick AccessLog [:AccessLog] = [] new(, app).start end |
Instance Method Details
#start ⇒ Object
Starts the application on the available server with specified options.
56 57 58 59 60 61 62 63 64 |
# File 'padrino-core/lib/padrino-core/server.rb', line 56 def start puts "=> Padrino/#{Padrino.version} has taken the stage #{Padrino.env} at http://#{[:Host]}:#{[: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 [:daemonize] end |