Class: Honeybadger::Rack::UserInformer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/honeybadger/rack/user_informer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ UserInformer

Returns a new instance of UserInformer.



8
9
10
11
# File 'lib/honeybadger/rack/user_informer.rb', line 8

def initialize(app, config)
  @app = app
  @config = config
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/honeybadger/rack/user_informer.rb', line 17

def call(env)
  status, headers, body = @app.call(env)
  if env['honeybadger.error_id']
    new_body = []
    replace  = replacement(env['honeybadger.error_id'])
    body.each do |chunk|
      new_body << chunk.gsub("<!-- HONEYBADGER ERROR -->", replace)
    end
    body.close if body.respond_to?(:close)
    headers['Content-Length'] = new_body.reduce(0) { |a,e| a += e.bytesize }.to_s
    body = new_body
  end
  [status, headers, body]
end

#replacement(with) ⇒ Object



13
14
15
# File 'lib/honeybadger/rack/user_informer.rb', line 13

def replacement(with)
  config[:'user_informer.info'].gsub(/\{\{\s*error_id\s*\}\}/, with.to_s)
end