Class: PeakFlowUtils::NotifierErrorParser

Inherits:
Object
  • Object
show all
Defined in:
lib/peak_flow_utils/notifier_error_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#backtraceObject (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

#environmentObject (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

#errorObject (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_pathObject (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_numberObject (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_environmentObject



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_numberObject



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_ipObject



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

#urlObject



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_agentObject



50
51
52
# File 'lib/peak_flow_utils/notifier_error_parser.rb', line 50

def user_agent
  environment["HTTP_USER_AGENT"]
end