Module: Faultline::LoggedExceptionsHelper
- Defined in:
- app/helpers/faultline/logged_exceptions_helper.rb
Instance Method Summary collapse
-
#active_filter_pills ⇒ Object
Active filter pills for the filter bar.
-
#exception_count_for(exception_class) ⇒ Object
Count occurrences of a specific exception class.
-
#exception_trend_data(days: 7) ⇒ Object
Simple sparkline data for stats.
- #filtered? ⇒ Boolean
-
#format_backtrace(backtrace, limit: nil) ⇒ Object
Format backtrace for display with optional collapse.
- #listify(text) ⇒ Object
- #page_title(text) ⇒ Object
- #pretty_exception_date(exception) ⇒ Object
-
#pretty_format(text) ⇒ Object
Rescue textilize call if RedCloth is not available.
-
#severity_for(exception) ⇒ Object
Severity badge class based on exception type.
-
#sort_link(search, attribute, name = nil, **options, &block) ⇒ Object
Sort link helper for Ransack-compatible table headers.
Instance Method Details
#active_filter_pills ⇒ Object
Active filter pills for the filter bar
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 97 def active_filter_pills pills = [] if params[:q].present? params[:q].each do |key, value| next if value.blank? pills << { label: key.to_s.sub(/_(cont|eq|gteq|lteq)$/, "").humanize, value: value, param: "q[#{key}]" } end end if params[:date_ranges_filter].present? label = { "1" => "Today", "3" => "Last 3 days", "7" => "Last 7 days", "30" => "Last 30 days" }[params[:date_ranges_filter]] || "Custom" pills << { label: label, value: params[:date_ranges_filter], param: "date_ranges_filter" } end pills end |
#exception_count_for(exception_class) ⇒ Object
Count occurrences of a specific exception class
116 117 118 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 116 def exception_count_for(exception_class) LoggedException.where(exception_class: exception_class).count end |
#exception_trend_data(days: 7) ⇒ Object
Simple sparkline data for stats
121 122 123 124 125 126 127 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 121 def exception_trend_data(days: 7) data = (0...days).reverse_each.map do |i| date = i.days.ago.to_date LoggedException.where(created_at: date.beginning_of_day..date.end_of_day).count end data end |
#filtered? ⇒ Boolean
31 32 33 34 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 31 def filtered? [:query, :date_ranges_filter, :exception_names_filter, :controller_actions_filter].any? { |p| params[p] } || params[:q].present? end |
#format_backtrace(backtrace, limit: nil) ⇒ Object
Format backtrace for display with optional collapse
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 67 def format_backtrace(backtrace, limit: nil) limit ||= Faultline.configuration.backtrace_limit lines = backtrace.to_s.split("\n") if lines.length > limit collapsed = lines[0...limit] remaining = lines[limit..] { visible: collapsed.join("\n"), hidden: remaining.join("\n"), hidden_count: remaining.length } else { visible: lines.join("\n"), hidden: nil, hidden_count: 0 } end end |
#listify(text) ⇒ Object
36 37 38 39 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 36 def listify(text) list_items = text.scan(/^\s*\* (.+)/).map { |match| content_tag(:li, match.first) } content_tag(:ul, list_items) end |
#page_title(text) ⇒ Object
41 42 43 44 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 41 def page_title(text) title = [Faultline.application_name.presence, text].compact.join(" :: ") content_for(:title, title) end |
#pretty_exception_date(exception) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 5 def pretty_exception_date(exception) if Faultline.configuration.date_format return exception.created_at.strftime(Faultline.configuration.date_format) end time = exception.created_at diff = Time.current - time case when diff < 60 "#{(diff).to_i}s ago" when diff < 3600 "#{(diff / 60).to_i}m ago" when diff < 86400 "#{(diff / 3600).to_i}h ago" when diff < 604800 "#{(diff / 86400).to_i}d ago" when Date.today == time.to_date "Today, #{time.strftime('%I:%M %p')}" when Date.yesterday == time.to_date "Yesterday, #{time.strftime('%I:%M %p')}" else time.strftime('%b %d, %Y %I:%M %p') end end |
#pretty_format(text) ⇒ Object
Rescue textilize call if RedCloth is not available.
47 48 49 50 51 52 53 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 47 def pretty_format(text) begin textilize(text).html_safe rescue simple_format(text).html_safe end end |
#severity_for(exception) ⇒ Object
Severity badge class based on exception type
85 86 87 88 89 90 91 92 93 94 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 85 def severity_for(exception) case exception.exception_class when /Timeout|Slow|Performance/i "warning" when /404|NotFound|Missing/i "info" else "danger" end end |
#sort_link(search, attribute, name = nil, **options, &block) ⇒ Object
Sort link helper for Ransack-compatible table headers.
56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/faultline/logged_exceptions_helper.rb', line 56 def sort_link(search, attribute, name = nil, **, &block) name ||= attribute.to_s.humanize if defined?(Ransack) && search.respond_to?(:result) Ransack::Helpers::FormHelper.instance_method(:sort_link).bind(self).call(search, attribute, name, **, &block) else link_to name, "#", **, &block end end |