Class: PeakFlowUtils::NotifierErrorParser
- Inherits:
-
Object
- Object
- PeakFlowUtils::NotifierErrorParser
- Defined in:
- lib/peak_flow_utils/notifier_error_parser.rb
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
Instance Method Summary collapse
- #cleaned_environment ⇒ Object
- #detect_file_path_and_line_number ⇒ Object
-
#initialize(backtrace:, environment:, error:) ⇒ NotifierErrorParser
constructor
A new instance of NotifierErrorParser.
- #remote_ip ⇒ Object
- #url ⇒ Object
- #user_agent ⇒ Object
Constructor Details
#initialize(backtrace:, environment:, error:) ⇒ NotifierErrorParser
Returns a new instance of NotifierErrorParser.
4 5 6 7 8 9 10 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 4 def initialize(backtrace:, environment:, error:) @backtrace = backtrace @environment = environment || {} @error = error detect_file_path_and_line_number end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
2 3 4 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 2 def backtrace @backtrace end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
2 3 4 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 2 def environment @environment end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
2 3 4 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 2 def error @error end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
2 3 4 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 2 def file_path @file_path end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
2 3 4 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 2 def line_number @line_number end |
Instance Method Details
#cleaned_environment ⇒ Object
29 30 31 32 33 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 29 def cleaned_environment environment.reject do |key, _value| key.start_with?("action_controller.", "action_dispatch.", "puma.", "rack.") || key == "warden" end end |
#detect_file_path_and_line_number ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 12 def detect_file_path_and_line_number backtrace.each do |trace| match = trace.match(/^((.+)\.([A-z]{2,4})):(\d+)(:|$)/) next unless match file_path = match[1] line_number = match[4].to_i next if file_path.include?("/.rvm/") @file_path ||= file_path @line_number ||= line_number break end end |
#remote_ip ⇒ Object
35 36 37 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 35 def remote_ip environment["HTTP_X_FORWARDED_FOR"] || environment["REMOTE_ADDR"] end |
#url ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 39 def url return unless environment["REQUEST_URI"] url = "http" url << "s" if environment["SERVER_PORT"] == 443 || environment["rack.url_scheme"] == "https" || environment["HTTPS"] == "on" url << "://" url << environment["HTTP_HOST"] url << environment["REQUEST_URI"] url end |
#user_agent ⇒ Object
50 51 52 |
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 50 def user_agent environment["HTTP_USER_AGENT"] end |