From 36aa7be34e159e376a384de40d6e5f663a618f3c Mon Sep 17 00:00:00 2001 From: Marcin Ciunelis Date: Fri, 5 Oct 2012 15:43:22 +0200 Subject: [PATCH] - use BacktraceLine methods instead of hask keys - add BacktraceLine#file_relative --- app/helpers/notices_helper.rb | 18 +++++++++--------- app/models/backtrace_line.rb | 5 +++++ app/views/issue_trackers/fogbugz_body.txt.erb | 2 +- app/views/issue_trackers/github_issues_body.txt.erb | 2 +- app/views/issue_trackers/lighthouseapp_body.txt.erb | 2 +- app/views/issue_trackers/pivotal_body.txt.erb | 2 +- app/views/issue_trackers/textile_body.txt.erb | 2 +- app/views/notices/_atom_entry.html.haml | 4 ++-- app/views/notices/_backtrace_line.html.haml | 6 +++--- 9 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/helpers/notices_helper.rb b/app/helpers/notices_helper.rb index 6bd5073..6a2502c 100644 --- a/app/helpers/notices_helper.rb +++ b/app/helpers/notices_helper.rb @@ -18,24 +18,24 @@ module NoticesHelper end def filepath_parts(file) - [file.split('/').last, file.gsub('[PROJECT_ROOT]', '')] + [file.split('/').last, file] end def link_to_github(app, line, text = nil) - file_name, file_path = filepath_parts(line['file']) - href = "%s#L%s" % [app.github_url_to_file(file_path), line['number']] + file_name, file_path = filepath_parts(line.file) + href = "%s#L%s" % [app.github_url_to_file(file_path), line.number] link_to(text || file_name, href, :target => '_blank') end def link_to_bitbucket(app, line, text = nil) - file_name, file_path = filepath_parts(line['file']) - href = "%s#cl-%s" % [app.bitbucket_url_to_file(file_path), line['number']] + file_name, file_path = filepath_parts(line.file) + href = "%s#cl-%s" % [app.bitbucket_url_to_file(file_path), line.number] link_to(text || file_name, href, :target => '_blank') end def link_to_issue_tracker_file(app, line, text = nil) - file_name, file_path = filepath_parts(line['file']) - href = app.issue_tracker.url_to_file(file_path, line['number']) + file_name, file_path = filepath_parts(line.file_relative) + href = app.issue_tracker.url_to_file(file_path, line.number) link_to(text || file_name, href, :target => '_blank') end @@ -55,7 +55,7 @@ module NoticesHelper end def path_for_backtrace_line(line) - path = File.dirname(line['file']) + path = File.dirname(line.file) return '' if path == '.' # Remove [PROJECT_ROOT] path.gsub!('[PROJECT_ROOT]/', '') @@ -65,7 +65,7 @@ module NoticesHelper end def file_for_backtrace_line(line) - file = File.basename(line['file']) + file = File.basename(line.file) end end diff --git a/app/models/backtrace_line.rb b/app/models/backtrace_line.rb index ff818f8..d513948 100644 --- a/app/models/backtrace_line.rb +++ b/app/models/backtrace_line.rb @@ -17,5 +17,10 @@ class BacktraceLine def in_app? !!(file =~ IN_APP_REGEXP) end + + def file_relative + file.to_s.sub(/^\[PROJECT_ROOT\]/, '') + end + end diff --git a/app/views/issue_trackers/fogbugz_body.txt.erb b/app/views/issue_trackers/fogbugz_body.txt.erb index ff1a9bd..3a7a9e4 100644 --- a/app/views/issue_trackers/fogbugz_body.txt.erb +++ b/app/views/issue_trackers/fogbugz_body.txt.erb @@ -20,7 +20,7 @@ Backtrace <% for line in notice.backtrace_lines %> - <%= line['number'] %>: <%= line['file'].to_s.sub(/^\[PROJECT_ROOT\]/, '') %> + <%= line.number %>: <%= line.file_relative %> <% end %> Environment diff --git a/app/views/issue_trackers/github_issues_body.txt.erb b/app/views/issue_trackers/github_issues_body.txt.erb index f3efb45..44d52e6 100644 --- a/app/views/issue_trackers/github_issues_body.txt.erb +++ b/app/views/issue_trackers/github_issues_body.txt.erb @@ -27,7 +27,7 @@ ## Backtrace ## ``` -<% for line in notice.backtrace_lines %><%= line['number'] %>: <%= line['file'].to_s.sub(/^\[PROJECT_ROOT\]/, '') %> -> **<%= line['method'] %>** +<% for line in notice.backtrace_lines %><%= line.number %>: <%= line.file_relative %> -> **<%= line.method %>** <% end %> ``` diff --git a/app/views/issue_trackers/lighthouseapp_body.txt.erb b/app/views/issue_trackers/lighthouseapp_body.txt.erb index a5313e9..dca1e65 100644 --- a/app/views/issue_trackers/lighthouseapp_body.txt.erb +++ b/app/views/issue_trackers/lighthouseapp_body.txt.erb @@ -23,7 +23,7 @@ ## Backtrace ## - <% for line in notice.backtrace_lines %><%= line['number'] %>: <%= line['file'].to_s.sub(/^\[PROJECT_ROOT\]/, '') %> -> **<%= line['method'] %>** + <% for line in notice.backtrace_lines %><%= line.number %>: <%= line.file_relative %> -> **<%= line.method %>** <% end %> diff --git a/app/views/issue_trackers/pivotal_body.txt.erb b/app/views/issue_trackers/pivotal_body.txt.erb index 515a347..7c2b80a 100644 --- a/app/views/issue_trackers/pivotal_body.txt.erb +++ b/app/views/issue_trackers/pivotal_body.txt.erb @@ -12,6 +12,6 @@ See this exception on Errbit: <%= app_problem_url problem.app, problem %> <%= pretty_hash notice.session %> Backtrace: - <%= notice.backtrace_lines[0..4].map { |line| "#{line['number']}: #{line['file'].to_s.sub(/^\[PROJECT_ROOT\]/, '')} -> *#{line['method']}*" }.join "\n" %> + <%= notice.backtrace_lines[0..4].map { |line| "#{line.number}: #{line.file_relative} -> *#{line.method}*" }.join "\n" %> <% end %> diff --git a/app/views/issue_trackers/textile_body.txt.erb b/app/views/issue_trackers/textile_body.txt.erb index 6dd6192..79315b8 100644 --- a/app/views/issue_trackers/textile_body.txt.erb +++ b/app/views/issue_trackers/textile_body.txt.erb @@ -32,7 +32,7 @@ h2. Session h2. Backtrace | Line | File | Method | -<% for line in notice.backtrace_lines %>| <%= line['number'] %> | <%= line['file'].to_s.sub(/^\[PROJECT_ROOT\]/, '') %> | *<%= line['method'] %>* | +<% for line in notice.backtrace_lines %>| <%= line.number %> | <%= line.file_relative %> | *<%= line.method %>* | <% end %> h2. Environment diff --git a/app/views/notices/_atom_entry.html.haml b/app/views/notices/_atom_entry.html.haml index 8021c50..1e15b52 100644 --- a/app/views/notices/_atom_entry.html.haml +++ b/app/views/notices/_atom_entry.html.haml @@ -25,10 +25,10 @@ - for line in notice.backtrace_lines %tr %td - = "#{line['number']}:" + = "#{line.number}:"    %td - = raw "#{h line['file'].sub(/^\[PROJECT_ROOT\]/, '')} -> #{content_tag :strong, h(line['method'])}" + = raw "#{h line.file_relative} -> #{content_tag :strong, h(line.method)}" %h3 Environment %table diff --git a/app/views/notices/_backtrace_line.html.haml b/app/views/notices/_backtrace_line.html.haml index ccc9a5a..be8362d 100644 --- a/app/views/notices/_backtrace_line.html.haml +++ b/app/views/notices/_backtrace_line.html.haml @@ -3,7 +3,7 @@ = link_to_source_file(@app, line) do %span.path>= path_for_backtrace_line(line) %span.file>= file_for_backtrace_line(line) - - if line['number'].present? - %span.number>= ":#{line['number']}" + - if line.number.present? + %span.number>= ":#{line.number}" → - %span.method= line['method'] + %span.method= line.method -- libgit2 0.21.2