Class: Noise::Notification
- Inherits:
-
Object
- Object
- Noise::Notification
- Defined in:
- lib/noise/notification.rb
Overview
Provides detailed information about exception and request context.
Constant Summary collapse
Class Method Summary collapse
-
.extract(key, extractor) ⇒ void
Extract info from request and it to Bugsnag notification.
- .register(error_class, severity:) ⇒ Object
Instance Method Summary collapse
-
#initialize(error, env) ⇒ Notification
constructor
A new instance of Notification.
-
#severity ⇒ String
Error severity.
- #to_hash ⇒ {String, Any}
-
#user_info ⇒ Hash
User info.
Constructor Details
#initialize(error, env) ⇒ Notification
Returns a new instance of Notification.
56 57 58 59 |
# File 'lib/noise/notification.rb', line 56 def initialize(error, env) @error = error @env = env end |
Class Method Details
.extract(key, extractor) ⇒ void
This method returns an undefined value.
Extract info from request and it to Bugsnag notification
47 48 49 |
# File 'lib/noise/notification.rb', line 47 def extract(key, extractor) extractors[key] = extractor end |
.register(error_class, severity:) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/noise/notification.rb', line 27 def register(error_class, severity:) if SEVERITIES.include?(severity) severities[error_class.to_s] = severity else fail ArgumentError, "Wrong severity `#{severity}`, allowed: #{SEVERITIES}" end end |
Instance Method Details
#severity ⇒ String
Returns Error severity.
69 70 71 |
# File 'lib/noise/notification.rb', line 69 def severity severities[@error.class.name].to_s end |
#to_hash ⇒ {String, Any}
62 63 64 65 66 |
# File 'lib/noise/notification.rb', line 62 def to_hash extractors.except('user').transform_values do |extractor| extractor.new.call(@env) end end |
#user_info ⇒ Hash
Returns User info.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/noise/notification.rb', line 74 def user_info user = if extractors.key?('user') extractors['user'].new.call(@env) else {} end fail '`name` key is reserved to identify error itself' if user.key?('name') user.merge('name' => request.uuid) end |