Class: Captivity

Inherits:
Object
  • Object
show all
Defined in:
lib/captivity.rb

Defined Under Namespace

Classes: LoggerWithWriteMethod

Constant Summary collapse

VERSION =
'0.0.1'

Instance Method Summary collapse

Constructor Details

#initialize(app, logger_or_stream = STDERR) ⇒ Captivity

Returns a new instance of Captivity.



19
20
21
22
# File 'lib/captivity.rb', line 19

def initialize(app, logger_or_stream = STDERR)
  @logger = configure_logger_or_stream(logger_or_stream)
  @app = Rack::CommonLogger.new(app, @logger)
end

Instance Method Details

#call(env) ⇒ Object

Calls the contained application. The application will receive the defined Logger object in the “captivity.logger” of the env hash



26
27
28
29
30
31
32
33
# File 'lib/captivity.rb', line 26

def call(env)
  env["captivity.logger"] = @logger
  @app.call(env)
rescue StandardError, LoadError, SyntaxError => exception
  log_exception(exception)
  # Reraise to display using Rack
  raise exception
end