class Tennpipes::Server
This module builds a Tennpipes
server to run the project based on available handlers.
Constants
Public Class Methods
new(options, app)
click to toggle source
# File lib/tennpipes-base/server.rb, line 52 def initialize(options, app) @options, @app = options, app end
start(app, options={})
click to toggle source
Starts the application on the available server with specified options.
# File lib/tennpipes-base/server.rb, line 41 def self.start(app, options={}) options = options.to_hash.symbolize_keys 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 if options[:server].blank? # disable Webrick AccessLog options[:AccessLog] = [] new(options, app).start end
Private Class Methods
detect_address(options)
click to toggle source
Detects Host and Port for Rack server.
# File lib/tennpipes-base/server.rb, line 112 def self.detect_address(options) address = DEFAULT_ADDRESS.merge options.slice(:Host, :Port) address[:Host] = options[:host] if options[:host].present? address[:Port] = options[:port] if options[:port].present? address end
detect_rack_handler()
click to toggle source
Detects the supported handler to use.
@example
detect_rack_handler => <ThinHandler>
# File lib/tennpipes-base/server.rb, line 84 def self.detect_rack_handler Handlers.each do |handler| begin return handler if Rack::Handler.get(handler.to_s.downcase) rescue LoadError rescue NameError end end fail "Server handler (#{Handlers.join(', ')}) not found." end
parse_server_options(options)
click to toggle source
Parses an array of server options.
# File lib/tennpipes-base/server.rb, line 105 def self.parse_server_options(options) parsed_server_options = Array(options).flat_map{ |option| option.split('=', 2) } Hash[*parsed_server_options].symbolize_keys end
prepare_pid(pid)
click to toggle source
Prepares a directory for pid file.
# File lib/tennpipes-base/server.rb, line 97 def self.prepare_pid(pid) pid = 'tmp/pids/server.pid' if pid.blank? FileUtils.mkdir_p(File.dirname(pid)) File.expand_path(pid) end
Public Instance Methods
app()
click to toggle source
The application the server will run.
# File lib/tennpipes-base/server.rb, line 68 def app @app end
Also aliased as: wrapped_app
options()
click to toggle source
# File lib/tennpipes-base/server.rb, line 73 def options @options end
start()
click to toggle source
Starts the application on the available server with specified options.
Calls superclass method
# File lib/tennpipes-base/server.rb, line 57 def start puts "=> Tennpipes/#{Tennpipes.version} has taken the stage #{Tennpipes.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 "<= Tennpipes leaves the gun, takes the cannoli" unless options[:daemonize] end