Class: RailsInstrument::Middleware
- Inherits:
-
Object
- Object
- RailsInstrument::Middleware
- Defined in:
- lib/rails_instrument.rb
Overview
:nodoc:
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
39 40 41 |
# File 'lib/rails_instrument.rb', line 39 def initialize(app, = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rails_instrument.rb', line 43 def call(env) RailsInstrument.reset! status, headers, body = @app.call(env) begin headers["X-View-Runtime"] = (view_runtime / 1000).to_s headers["X-DB-Runtime"] = (db_runtime / 1000).to_s headers["X-DB-Query-Count"] = sql_count.to_s if html_reponse?(headers) new_body = Rack::Response.new([], status, headers) body.each do |fragment| new_body.write fragment.gsub("</body>", "#{}</body>") end body = new_body end rescue => e headers["X-Rails-Instrument"] = "Error" end [status, headers, body] end |