class StreetLights
Public Class Methods
new(app)
click to toggle source
# File lib/street_lights.rb, line 6 def initialize(app) @app = app @street_lights_dir = 'street_lights/' unless File.exists?(@street_lights_dir) FileUtils.mkdir_p(@street_lights_dir) end shutdown_behaviour = proc do FileUtils.rm(street_light) if File.exists?(street_light) end trap('QUIT', &shutdown_behaviour) trap('TERM', &shutdown_behaviour) trap('EXIT', &shutdown_behaviour) trap('KILL', &shutdown_behaviour) end
Public Instance Methods
call(env)
click to toggle source
# File lib/street_lights.rb, line 25 def call(env) File.open(street_light, 'w+') do |file| file.puts "#{Process.pid.to_s.to_ansi.red.to_s} #{env['HTTP_HOST']} #{env['REQUEST_PATH']}" end status, headers, response = @app.call(env) File.open(street_light, 'w+') do |file| file.puts "#{Process.pid.to_s.to_ansi.green.to_s}" end [status, headers, response] end
street_light()
click to toggle source
# File lib/street_lights.rb, line 21 def street_light @street_light ||= "#{@street_lights_dir}/#{Process.pid}" end