lib/rack/handler/toycol.rb in toycol-0.3.0 vs lib/rack/handler/toycol.rb in toycol-0.3.1
- old
+ new
@@ -1,13 +1,14 @@
# frozen_string_literal: true
-require "rack"
require "rack/handler"
module Rack
module Handler
class Toycol
+ extend ::Toycol::Helper
+
class << self
attr_writer :preferred_background_server, :host, :port
def run(app, _ = {})
@app = app
@@ -25,36 +26,36 @@
private
def select_background_server
case @preferred_background_server
when "puma"
- return "puma" if puma_requireable?
+ return "puma" if try_require_puma_handler
raise LoadError, "Puma is not installed in your environment."
when nil
- puma_requireable? ? "puma" : "build_in"
+ try_require_puma_handler ? "puma" : "builtin"
else
- "build_in"
+ "builtin"
end
rescue LoadError
Process.kill(:INT, Process.ppid)
abort
end
- def puma_requireable?
+ def try_require_puma_handler
require "rack/handler/puma"
true
rescue LoadError
false
end
def run_background_server
case select_background_server
when "puma"
- puts "Toycol starts Puma in single mode, listening on unix://#{::Toycol::UNIX_SOCKET_PATH}"
+ 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
- puts "Toycol starts build-in server, listening on unix://#{::Toycol::UNIX_SOCKET_PATH}"
+ 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
end
end