Class: RailsInfo::StackTracePresenter

Inherits:
Presenter
  • Object
show all
Defined in:
app/presenters/rails_info/stack_trace_presenter.rb

Instance Method Summary collapse

Methods inherited from Presenter

#subject=

Constructor Details

#initialize(subject, options = {}) ⇒ StackTracePresenter

Returns a new instance of StackTracePresenter.



2
3
4
5
6
7
8
9
10
11
12
# File 'app/presenters/rails_info/stack_trace_presenter.rb', line 2

def initialize(subject, options = {})
  super(subject, options)
  
  options[:stack_trace] ||= {}
  
  @stack_trace = ::RailsInfo::StackTrace.new(
    options[:stack_trace][:body], rails_root: options[:stack_trace][:rails_root], 
    request: options[:stack_trace][:request], exception: options[:stack_trace][:exception],
    show_all: options[:stack_trace][:show_all], lines_of_code_around: options[:stack_trace][:lines_of_code_around]
  )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RailsInfo::Presenter

Instance Method Details

#accordion(type = 'full') ⇒ Object

Parameters

type: full or application



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/presenters/rails_info/stack_trace_presenter.rb', line 30

def accordion(type = 'full')
   :div, class: 'accordions' do
    html = ''
    
    hash = if type == 'application' 
      if @stack_trace.hash.keys.first.match(' of ') 
        @stack_trace.hash.select{|f,c| f.match("of #{rails_root}")}
      else
        @stack_trace.hash.select{|f,c| f.match(rails_root)}
      end
    else 
      @stack_trace.hash
    end
         
    hash.each do |file, code|
      file_without_rails_root = file.dup
     
      if file_without_rails_root.match(rails_root)
        file_without_rails_root.gsub!(rails_root, '') 
      end

      highligted_line_number = code[:highlighted_line_numbers].is_a?(Array) ? code[:highlighted_line_numbers].first : code[:highlighted_line_numbers]  
      link_to_line_number = link_to file_without_rails_root, "##{file_without_rails_root.parameterize}"
      html +=  :h3, raw("        #{file_without_rails_root}")
      code_presenter = ::RailsInfo::CodePresenter.new(@subject, code.merge(highlighted_number_name: file_without_rails_root))
      
      height = (((@stack_trace.lines_of_code_around * 2) + 1) * 18).round
      
      html +=  :div, raw(code_presenter.table), style: "max-height:#{height}px; overflow: auto"
    end  
    
    raw html
  end  
end

#headerObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/presenters/rails_info/stack_trace_presenter.rb', line 14

def header
  html = ''
  
  if @stack_trace.exception
    html += (:h1, h(@stack_trace.title)) 
    html += (:pre, @stack_trace.message, class: 'stack_trace_message')
  end
  
  html += (:p, (:code, "Rails.root: #{rails_root}"))
  
  html
end

#request_tabObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/presenters/rails_info/stack_trace_presenter.rb', line 65

def request_tab
  clean_params = request.filtered_parameters.clone
  clean_params.delete("action")
  clean_params.delete("controller")

  request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
  
  html = (:p) do
    (:strong, 'Parameters:') + (:pre, h(request_dump))
  end
  
  [:session, :env].each do |method|
    html += (:p) do
      link_to "Show #{method} dump", '#', onclick: "document.getElementById('#{method}_dump').style.display='block'; return false;"
    end
    
    html += (:div, id: "#{method}_dump", style: 'display:none') do
      content = method == :env ? request.env.slice(*request.class::ENV_METHODS) : request.send(method) 
       :pre, debug_hash(content)
    end 
  end
  
  html
end

#response_tabObject



90
91
92
93
94
# File 'app/presenters/rails_info/stack_trace_presenter.rb', line 90

def response_tab
   :p do
    (:strong, 'Headers:') + (:pre, h(defined?(@response) ? response.headers.inspect.gsub(',', ",\n") : 'None'))
  end
end