Class: HoptoadNotifier::UserInformer

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ UserInformer

Returns a new instance of UserInformer.



3
4
5
# File 'lib/hoptoad_notifier/user_informer.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/hoptoad_notifier/user_informer.rb', line 11

def call(env)
  status, headers, body = @app.call(env)
  if env['hoptoad.error_id']
    body.each_with_index do |chunk, i|
      body[i] = chunk.to_s.gsub("<!-- HOPTOAD ERROR -->", replacement(env['hoptoad.error_id']))
    end
    headers['Content-Length'] = body.sum(&:length).to_s
  end
  [status, headers, body]
end

#replacement(with) ⇒ Object



7
8
9
# File 'lib/hoptoad_notifier/user_informer.rb', line 7

def replacement(with)
  @replacement ||= HoptoadNotifier.configuration.user_information.gsub(/\{\{\s*error_id\s*\}\}/, with.to_s)
end