Class: Rack::Hoptoad

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

Overview

Catches all exceptions raised from the app it wraps and posts the results to hoptoad.

Constant Summary collapse

VERSION =
'0.1.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, api_key = nil, rack_environment = 'RACK_ENV') {|_self| ... } ⇒ Hoptoad

Returns a new instance of Hoptoad.

Yields:

  • (_self)

Yield Parameters:

  • _self (Rack::Hoptoad)

    the object that the method was called on



13
14
15
16
17
18
19
20
# File 'lib/rack/hoptoad.rb', line 13

def initialize(app, api_key = nil, rack_environment = 'RACK_ENV')
  @app                 = app
  @api_key             = api_key
  @report_under        = %w(staging production)
  @rack_environment    = rack_environment
  @environment_filters = %w(AWS_ACCESS_KEY  AWS_SECRET_ACCESS_KEY AWS_ACCOUNT SSH_AUTH_SOCK)
  yield self if block_given?
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



11
12
13
# File 'lib/rack/hoptoad.rb', line 11

def api_key
  @api_key
end

#environment_filtersObject

Returns the value of attribute environment_filters.



11
12
13
# File 'lib/rack/hoptoad.rb', line 11

def environment_filters
  @environment_filters
end

#rack_environmentObject

Returns the value of attribute rack_environment.



11
12
13
# File 'lib/rack/hoptoad.rb', line 11

def rack_environment
  @rack_environment
end

#report_underObject

Returns the value of attribute report_under.



11
12
13
# File 'lib/rack/hoptoad.rb', line 11

def report_under
  @report_under
end

Instance Method Details

#call(env) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rack/hoptoad.rb', line 22

def call(env)
  status, headers, body =
    begin
      @app.call(env)
    rescue StandardError, LoadError, SyntaxError => boom
      # TODO don't allow exceptions from send_notification to
      # propogate
      notified = send_notification boom, env
      env['hoptoad.notified'] = notified
      raise
    end
  send_notification env['rack.exception'], env if env['rack.exception']
  [status, headers, body]
end

#environment_filter_keysObject



37
38
39
# File 'lib/rack/hoptoad.rb', line 37

def environment_filter_keys
  @environment_filters.flatten
end