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.

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
'0.1.5'

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


15
16
17
18
19
20
21
22
23
24
# File 'lib/rack/hoptoad.rb', line 15

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)
  @notifier_class      = Toadhopper
  @failsafe            = $stderr
  yield self if block_given?
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key


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

def api_key
  @api_key
end

#environment_filtersObject

Returns the value of attribute environment_filters


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

def environment_filters
  @environment_filters
end

#failsafeObject

Returns the value of attribute failsafe


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

def failsafe
  @failsafe
end

#notifier_classObject

Returns the value of attribute notifier_class


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

def notifier_class
  @notifier_class
end

#rack_environmentObject

Returns the value of attribute rack_environment


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

def rack_environment
  @rack_environment
end

#report_underObject

Returns the value of attribute report_under


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

def report_under
  @report_under
end

Instance Method Details

#call(env) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rack/hoptoad.rb', line 26

def call(env)
  status, headers, body =
    begin
      @app.call(env)
    rescue StandardError, LoadError, SyntaxError => boom
      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


39
40
41
# File 'lib/rack/hoptoad.rb', line 39

def environment_filter_keys
  @environment_filters.flatten
end

#environment_filter_regexpsObject


43
44
45
46
47
# File 'lib/rack/hoptoad.rb', line 43

def environment_filter_regexps
  environment_filter_keys.map do |key|
    "^#{Regexp.escape(wrapped_key_for(key))}$"
  end
end