Class: StreetLights
- Inherits:
-
Object
- Object
- StreetLights
- Defined in:
- lib/street_lights.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ StreetLights
constructor
A new instance of StreetLights.
- #street_light ⇒ Object
Constructor Details
#initialize(app) ⇒ StreetLights
Returns a new instance of StreetLights.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Method Details
#call(env) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
21 22 23 |
# File 'lib/street_lights.rb', line 21 def street_light @street_light ||= "#{@street_lights_dir}/#{Process.pid}" end |