Class: ScoutApm::Instruments::MiddlewareSummary::MiddlewareSummaryWrapper
- Inherits:
-
Object
- Object
- ScoutApm::Instruments::MiddlewareSummary::MiddlewareSummaryWrapper
- Defined in:
- lib/scout_apm/instruments/middleware_summary.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ MiddlewareSummaryWrapper
constructor
A new instance of MiddlewareSummaryWrapper.
-
#method_missing(sym, *arguments, &block) ⇒ Object
Some code (found in resque_web initially) attempts to call methods directly on ‘MyApplication.app`, which is the middleware stack.
- #respond_to?(sym, include_private = false) ⇒ Boolean
Constructor Details
#initialize(app) ⇒ MiddlewareSummaryWrapper
Returns a new instance of MiddlewareSummaryWrapper.
50 51 52 |
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 50 def initialize(app) @app = app end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *arguments, &block) ⇒ Object
Some code (found in resque_web initially) attempts to call methods directly on ‘MyApplication.app`, which is the middleware stack. If it hits our middleware instead of the object at the root of the app that it expected, then a method it expects will not be there, and an error thrown.
Specifically, resque_web assumes ‘ResqueWeb::Engine.app.url_helpers` is a method call on rails router for its own Engine, when in fact, we’ve added a middleware before it.
So method_missing just proxies anything to the nested @app object
While method_missing is not very performant, this is only here to handle edge-cases in other code, and should not be regularly called
77 78 79 80 81 82 83 |
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 77 def method_missing(sym, *arguments, &block) if @app.respond_to?(sym) @app.send(sym, *arguments, &block) else super end end |
Instance Method Details
#call(env) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 54 def call(env) req = ScoutApm::RequestManager.lookup layer = ScoutApm::Layer.new("Middleware", "Summary") req.start_layer(layer) @app.call(env) ensure req.stop_layer end |
#respond_to?(sym, include_private = false) ⇒ Boolean
85 86 87 88 89 90 91 |
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 85 def respond_to?(sym, include_private = false) if @app.respond_to?(sym, include_private) true else super end end |