Class: Rack::Monitor::MonitorApp
- Inherits:
-
Object
- Object
- Rack::Monitor::MonitorApp
- Defined in:
- lib/rack/monitor/monitor_app.rb
Instance Method Summary collapse
- #call(env, options = {}) ⇒ Object
-
#initialize(app, options = {}) ⇒ MonitorApp
constructor
A new instance of MonitorApp.
Constructor Details
#initialize(app, options = {}) ⇒ MonitorApp
Returns a new instance of MonitorApp.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rack/monitor/monitor_app.rb', line 12 def initialize(app, ={}) @app = app @options = {:url=>'/rack_status'}.merge() sensor_class_names = Rack::Monitor.constants.reject { |s| %q(Sensor MonitorApp).include?(s) } @sensors = sensor_class_names.collect { |s| Rack::Monitor.const_get(s).new } @watches = {} if @options.has_key?(:watch) @options[:watch].each do |path| @watches[path] = [Request.new] end end end |
Instance Method Details
#call(env, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rack/monitor/monitor_app.rb', line 25 def call(env, ={}) if env["PATH_INFO"] == @options[:url] [200, {'Content-Type' => 'text/plain'}, [monitor_output]] else @sensors.each { |sensor| sensor.before(env) } if @watches.has_key?(env["PATH_INFO"]) @watches[env["PATH_INFO"]].each { |sensor| sensor.before(env) } end status, headers, body = @app.call(env) if @watches.has_key?(env["PATH_INFO"]) @watches[env["PATH_INFO"]].each { |sensor| sensor.after(env, status, headers, body) } end @sensors.each { |sensor| sensor.after(env, status, headers, body) } [status, headers, body] end end |