Class: Rack::ProcTitle
- Inherits:
-
Object
- Object
- Rack::ProcTitle
- Defined in:
- lib/rack/contrib/proctitle.rb
Overview
Middleware to update the process title ($0) with information about the current request. Based loosely on:
NOTE: This will not work properly in a multi-threaded environment.
Constant Summary collapse
- F =
::File
- PROGNAME =
F.basename($0)
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ProcTitle
constructor
A new instance of ProcTitle.
Constructor Details
#initialize(app) ⇒ ProcTitle
Returns a new instance of ProcTitle.
12 13 14 15 16 17 18 |
# File 'lib/rack/contrib/proctitle.rb', line 12 def initialize(app) @app = app @appname = Dir.pwd.split('/').reverse. find { |name| name !~ /^(\d+|current|releases)$/ } || PROGNAME @requests = 0 $0 = "#{PROGNAME} [#{@appname}] init ..." end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rack/contrib/proctitle.rb', line 20 def call(env) host, port = env['SERVER_NAME'], env['SERVER_PORT'] meth, path = env['REQUEST_METHOD'], env['PATH_INFO'] @requests += 1 $0 = "#{PROGNAME} [#{@appname}/#{port}] (#{@requests}) " \ "#{meth} #{path}" @app.call(env) end |