Class: RailsInfo::StackTrace
- Inherits:
-
Object
- Object
- RailsInfo::StackTrace
- Defined in:
- lib/rails_info/stack_trace.rb
Instance Method Summary collapse
- #exception ⇒ Object
- #hash ⇒ Object
-
#initialize(stack_trace, options = {}) ⇒ StackTrace
constructor
A new instance of StackTrace.
- #lines_of_code_around ⇒ Object
- #message ⇒ Object
- #rails_root ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(stack_trace, options = {}) ⇒ StackTrace
Returns a new instance of StackTrace.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rails_info/stack_trace.rb', line 2 def initialize(stack_trace, = {}) @request = [:request] @exception = [:exception] @rails_root = [:rails_root] || Rails.root.to_s @lines_of_code_around = [:lines_of_code_around] || 5 @show_all = [:show_all] if stack_trace.is_a?(String) && stack_trace.match('#') # parse RSpec style stack trace "# ./app/observers/assignment_observer.rb:65:in `after_save'" line_separator = if stack_trace.match(/\r\n/) "\r\n" elsif stack_trace.match(/\\n/) /\\n/ else "\n" end stack_trace = stack_trace.split(line_separator).map{|line|line.gsub('#', '').gsub('./', rails_root + '/')}.map(&:strip) elsif stack_trace.is_a?(String) && !stack_trace.strip.blank? raise NotImplementedError.new(stack_trace.inspect) end @stack_trace = stack_trace end |
Instance Method Details
#exception ⇒ Object
27 28 29 |
# File 'lib/rails_info/stack_trace.rb', line 27 def exception @exception end |
#hash ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/rails_info/stack_trace.rb', line 50 def hash return @hash if @hash @hash = {} parse_stack_trace @hash end |
#lines_of_code_around ⇒ Object
46 47 48 |
# File 'lib/rails_info/stack_trace.rb', line 46 def lines_of_code_around @lines_of_code_around end |
#message ⇒ Object
42 43 44 |
# File 'lib/rails_info/stack_trace.rb', line 42 def @exception. end |
#rails_root ⇒ Object
68 69 70 |
# File 'lib/rails_info/stack_trace.rb', line 68 def rails_root @rails_root end |
#request ⇒ Object
60 61 62 |
# File 'lib/rails_info/stack_trace.rb', line 60 def request @request end |
#response ⇒ Object
64 65 66 |
# File 'lib/rails_info/stack_trace.rb', line 64 def response @response end |
#title ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rails_info/stack_trace.rb', line 31 def title text = @exception.class.to_s if @request && @request.parameters['controller'] action = @request.parameters['action'].present? ? "##{@request.parameters['action']}" : '' text += " in #{@request.parameters['controller'].camelize}Controller#{action}" end text end |