Class: RssObserver::Middleware

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(app, handler) ⇒ Middleware

Returns a new instance of Middleware.

Parameters:

  • app (Object)

    Rails middleware instance

  • handler (Object)

    Handler that accepts memory change updates



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.

Parameters:

  • env (Hash)

    Full application environment hash

Returns:

  • (Array)

    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