Class: RailsInfo::StackTracePresenter
- Defined in:
- app/presenters/rails_info/stack_trace_presenter.rb
Instance Method Summary collapse
-
#accordion(type = 'full') ⇒ Object
Parameters.
- #header ⇒ Object
-
#initialize(subject, options = {}) ⇒ StackTracePresenter
constructor
A new instance of StackTracePresenter.
- #request_tab ⇒ Object
- #response_tab ⇒ Object
Methods inherited from Presenter
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, = {}) super(subject, ) [:stack_trace] ||= {} @stack_trace = ::RailsInfo::StackTrace.new( [:stack_trace][:body], rails_root: [:stack_trace][:rails_root], request: [:stack_trace][:request], exception: [:stack_trace][:exception], show_all: [:stack_trace][:show_all], lines_of_code_around: [: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') content_tag :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 += content_tag :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 += content_tag :div, raw(code_presenter.table), style: "max-height:#{height}px; overflow: auto" end raw html end end |
#header ⇒ Object
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 += content_tag(:h1, h(@stack_trace.title)) html += content_tag(:pre, @stack_trace., class: 'stack_trace_message') end html += content_tag(:p, content_tag(:code, "Rails.root: #{rails_root}")) html end |
#request_tab ⇒ Object
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 = content_tag(:p) do content_tag(:strong, 'Parameters:') + content_tag(:pre, h(request_dump)) end [:session, :env].each do |method| html += content_tag(:p) do link_to "Show #{method} dump", '#', onclick: "document.getElementById('#{method}_dump').style.display='block'; return false;" end html += content_tag(:div, id: "#{method}_dump", style: 'display:none') do content = method == :env ? request.env.slice(*request.class::ENV_METHODS) : request.send(method) content_tag :pre, debug_hash(content) end end html end |
#response_tab ⇒ Object
90 91 92 93 94 |
# File 'app/presenters/rails_info/stack_trace_presenter.rb', line 90 def response_tab content_tag :p do content_tag(:strong, 'Headers:') + content_tag(:pre, h(defined?(@response) ? response.headers.inspect.gsub(',', ",\n") : 'None')) end end |