Class: Depthcharge::Middleware

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, *outputs) ⇒ Middleware

Returns a new instance of Middleware.



6
7
8
9
10
11
12
13
14
15
# File 'lib/depthcharge/middleware.rb', line 6

def initialize(app, *outputs)
  @app = app
  @outputs = outputs.flatten.map do |output|
    if output.is_a?(String) || output.is_a?(Pathname)
      File.open(output, "w")
    else
      output
    end
  end
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



4
5
6
# File 'lib/depthcharge/middleware.rb', line 4

def app
  @app
end

#outputsObject (readonly)

Returns the value of attribute outputs.



4
5
6
# File 'lib/depthcharge/middleware.rb', line 4

def outputs
  @outputs
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
# File 'lib/depthcharge/middleware.rb', line 17

def call(env)
  status, headers, body = @app.call(env)
  RequestLogger.new(env, status, headers, body).log(outputs)
  [status, headers, body]
end