class Rack::Handler::Toycol
Attributes
host[W]
port[W]
preferred_background_server[W]
Public Class Methods
run(app, _ = {})
click to toggle source
# File lib/rack/handler/toycol.rb, line 13 def run(app, _ = {}) @app = app @host ||= ::Toycol::DEFAULT_HOST @port ||= "9292" if (child_pid = fork) ::Toycol::Proxy.new(@host, @port).start Process.waitpid(child_pid) else run_background_server end end
Private Class Methods
run_background_server()
click to toggle source
# File lib/rack/handler/toycol.rb, line 51 def run_background_server case select_background_server when "puma" logger "Start Puma in single mode, listening on unix://#{::Toycol::UNIX_SOCKET_PATH}" Rack::Handler::Puma.run(@app, **{ Host: ::Toycol::UNIX_SOCKET_PATH, Silent: true }) else logger "Start built-in server, listening on unix://#{::Toycol::UNIX_SOCKET_PATH}" ::Toycol::Server.run(@app, **{ Path: ::Toycol::UNIX_SOCKET_PATH, Port: @port }) end end
select_background_server()
click to toggle source
# File lib/rack/handler/toycol.rb, line 28 def select_background_server case @preferred_background_server when "puma" return "puma" if try_require_puma_handler raise LoadError, "Puma is not installed in your environment." when nil try_require_puma_handler ? "puma" : "builtin" else "builtin" end rescue LoadError Process.kill(:INT, Process.ppid) abort end
try_require_puma_handler()
click to toggle source
# File lib/rack/handler/toycol.rb, line 44 def try_require_puma_handler require "rack/handler/puma" true rescue LoadError false end