Class: RssObserver::Middleware
- Inherits:
-
Object
- Object
- RssObserver::Middleware
- Defined in:
- lib/rss_observer/middleware.rb
Overview
Class containing the Rails Middleware that
Constant Summary collapse
- UnsupportedHandlerError =
Class.new(RssObserver::Error)
Instance Method Summary collapse
-
#call(env) ⇒ Array
Status code, hash of headers, response body.
-
#initialize(app, handler) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, handler) ⇒ Middleware
Returns a new instance of Middleware.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rss_observer/middleware.rb', line 12 def initialize(app, handler) @app = app unless handler.respond_to?(:initial_memory) raise UnsupportedHandlerError, 'Handler must respond to the #initial_memory(kilobytes) method' end unless handler.respond_to?(:final_memory) raise UnsupportedHandlerError, 'Handler must respond to the #final_memory(kilobytes) method' end @handler = handler end |
Instance Method Details
#call(env) ⇒ Array
Returns Status code, hash of headers, response body.
26 27 28 29 30 31 |
# File 'lib/rss_observer/middleware.rb', line 26 def call(env) handler.initial_memory(current_memory) app.call(env).tap do handler.final_memory(current_memory) end end |