Class: ExceptionNotifier::SimplepushNotifier::SimplepushExceptionEvent
- Inherits:
-
Object
- Object
- ExceptionNotifier::SimplepushNotifier::SimplepushExceptionEvent
- Includes:
- BacktraceCleaner
- Defined in:
- lib/integrations/simplepush_notifier.rb
Overview
This class is responsible to format title and message from given exception and options.
Adapted from github.com/smartinez87/exception_notification/blob/master/lib/exception_notifier/datadog_notifier.rb
Version: committed on 27 Dec 2019
Released under MIT license: github.com/smartinez87/exception_notification/blob/master/MIT-LICENSE
Constant Summary collapse
- MAX_TITLE_LENGTH =
120- MAX_VALUE_LENGTH =
300- MAX_BACKTRACE_SIZE =
3
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #backtrace ⇒ Object
- #controller ⇒ Object
- #controller_subtitle ⇒ Object
- #formatted_backtrace ⇒ Object
- #formatted_body ⇒ Object
- #formatted_key_value(key, value) ⇒ Object
- #formatted_request ⇒ Object
- #formatted_session ⇒ Object
- #formatted_title ⇒ Object
-
#initialize(exception, options) ⇒ SimplepushExceptionEvent
constructor
A new instance of SimplepushExceptionEvent.
- #inspect_object(object) ⇒ Object
- #request ⇒ Object
- #title_prefix ⇒ Object
- #truncate(string, max) ⇒ Object
Constructor Details
#initialize(exception, options) ⇒ SimplepushExceptionEvent
Returns a new instance of SimplepushExceptionEvent.
39 40 41 42 |
# File 'lib/integrations/simplepush_notifier.rb', line 39 def initialize(exception, ) @exception = exception @options = end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
36 37 38 |
# File 'lib/integrations/simplepush_notifier.rb', line 36 def exception @exception end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
36 37 38 |
# File 'lib/integrations/simplepush_notifier.rb', line 36 def @options end |
Instance Method Details
#backtrace ⇒ Object
52 53 54 |
# File 'lib/integrations/simplepush_notifier.rb', line 52 def backtrace @backtrace ||= exception.backtrace ? clean_backtrace(exception) : [] end |
#controller ⇒ Object
48 49 50 |
# File 'lib/integrations/simplepush_notifier.rb', line 48 def controller @controller ||= [:env] && [:env]['action_controller.instance'] end |
#controller_subtitle ⇒ Object
126 127 128 |
# File 'lib/integrations/simplepush_notifier.rb', line 126 def controller_subtitle "#{controller.controller_name} #{controller.action_name}" if controller end |
#formatted_backtrace ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/integrations/simplepush_notifier.rb', line 102 def formatted_backtrace size = [backtrace.size, MAX_BACKTRACE_SIZE].min text = [] text << '# Backtrace' text << '````' size.times { |i| text << backtrace[i] } text << '````' text.join("\n") end |
#formatted_body ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/integrations/simplepush_notifier.rb', line 67 def formatted_body text = [] text << formatted_backtrace text << formatted_request if request text << formatted_session if request text.join("\n------------------\n") end |
#formatted_key_value(key, value) ⇒ Object
77 78 79 |
# File 'lib/integrations/simplepush_notifier.rb', line 77 def formatted_key_value(key, value) "#{key}: #{value}" end |
#formatted_request ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/integrations/simplepush_notifier.rb', line 81 def formatted_request text = [] text << '# Request' text << formatted_key_value('URL', request.url) text << formatted_key_value('HTTP Method', request.request_method) text << formatted_key_value('IP Address', request.remote_ip) text << formatted_key_value('Parameters', request.filtered_parameters.inspect) text << formatted_key_value('Timestamp', Time.current) text << formatted_key_value('Server', Socket.gethostname) text << formatted_key_value('Rails root', Rails.root) if defined?(Rails) && Rails.respond_to?(:root) text << formatted_key_value('Process', $PROCESS_ID) text.join("\n") end |
#formatted_session ⇒ Object
95 96 97 98 99 100 |
# File 'lib/integrations/simplepush_notifier.rb', line 95 def formatted_session text = [] text << '# Session' text << formatted_key_value('Data', request.session.to_hash) text.join("\n") end |
#formatted_title ⇒ Object
60 61 62 63 64 65 |
# File 'lib/integrations/simplepush_notifier.rb', line 60 def formatted_title title = "#{title_prefix}#{controller_subtitle} (#{exception.class}) #{exception..inspect}" truncate(title, MAX_TITLE_LENGTH) end |
#inspect_object(object) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/integrations/simplepush_notifier.rb', line 117 def inspect_object(object) case object when Hash, Array truncate(object.inspect, MAX_VALUE_LENGTH) else object.to_s end end |
#request ⇒ Object
44 45 46 |
# File 'lib/integrations/simplepush_notifier.rb', line 44 def request @request ||= ActionDispatch::Request.new([:env]) if [:env] end |
#title_prefix ⇒ Object
56 57 58 |
# File 'lib/integrations/simplepush_notifier.rb', line 56 def title_prefix [:title_prefix] || '' end |
#truncate(string, max) ⇒ Object
113 114 115 |
# File 'lib/integrations/simplepush_notifier.rb', line 113 def truncate(string, max) string.length > max ? "#{string[0...max]}..." : string end |