Class: Monolith::ExceptionsController::ExceptionInfo

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/monolith/exceptions_controller.rb

Overview

Inline ActiveModel-like object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ ExceptionInfo

Returns a new instance of ExceptionInfo.



65
66
67
# File 'app/controllers/monolith/exceptions_controller.rb', line 65

def initialize(exception)
  @exception = exception
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



63
64
65
# File 'app/controllers/monolith/exceptions_controller.rb', line 63

def exception
  @exception
end

Instance Method Details

#backtraceObject



77
78
79
# File 'app/controllers/monolith/exceptions_controller.rb', line 77

def backtrace
  exception.backtrace || []
end

#class_nameObject



69
70
71
# File 'app/controllers/monolith/exceptions_controller.rb', line 69

def class_name
  exception.class.name
end

#first_application_frameObject



95
96
97
98
# File 'app/controllers/monolith/exceptions_controller.rb', line 95

def first_application_frame
  # Try Application first, then any other group
  grouped_trace.find { |f| f[:group] == 'Application' } || grouped_trace.first
end

#grouped_traceObject



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/monolith/exceptions_controller.rb', line 81

def grouped_trace
  @grouped_trace ||= backtrace.map do |frame|
    file, line, method = parse_frame(frame)
    group = categorize_frame(frame)
    {
      frame: frame,
      file: file,
      line: line,
      method: method,
      group: group
    }
  end
end

#messageObject



73
74
75
# File 'app/controllers/monolith/exceptions_controller.rb', line 73

def message
  exception.message
end

#source_extractObject



100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/monolith/exceptions_controller.rb', line 100

def source_extract
  frame = first_application_frame
  return nil unless frame

  file = frame[:file]
  line = frame[:line]
  return nil unless file && line
  return nil unless File.exist?(file)

  extract_source(file, line)
end