Module: RailsErrorDashboard::Services::NotificationHelpers
- Defined in:
- lib/rails_error_dashboard/services/notification_helpers.rb
Overview
Shared helper methods for notification payload builders
Pure functions: no side effects, no HTTP calls, no database access. Used by all notification payload builders to avoid duplication.
Class Method Summary collapse
-
.dashboard_url(error_log) ⇒ String
Generate dashboard URL for an error.
-
.error_source(error_log) ⇒ String
Error source description for PagerDuty.
-
.extract_backtrace(backtrace, limit = 20) ⇒ Array<String>
Extract backtrace lines as an array.
-
.extract_first_backtrace_line(backtrace, length = 100) ⇒ String
Extract first backtrace line (truncated).
-
.format_time(time) ⇒ String
Format time for display.
-
.parse_request_params(params_json) ⇒ Hash
Parse request params JSON safely.
-
.platform_emoji(platform) ⇒ String
Platform emoji for Slack/text notifications.
-
.truncate_message(message, length = 500) ⇒ String
Truncate a message to a maximum length.
Class Method Details
.dashboard_url(error_log) ⇒ String
Generate dashboard URL for an error
15 16 17 18 |
# File 'lib/rails_error_dashboard/services/notification_helpers.rb', line 15 def dashboard_url(error_log) base_url = RailsErrorDashboard.configuration.dashboard_base_url || "http://localhost:3000" "#{base_url}/error_dashboard/errors/#{error_log.id}" end |
.error_source(error_log) ⇒ String
Error source description for PagerDuty
87 88 89 90 91 92 93 94 95 |
# File 'lib/rails_error_dashboard/services/notification_helpers.rb', line 87 def error_source(error_log) if error_log.controller_name && error_log.action_name "#{error_log.controller_name}##{error_log.action_name}" elsif error_log.request_url error_log.request_url else error_log.platform || "Rails Application" end end |
.extract_backtrace(backtrace, limit = 20) ⇒ Array<String>
Extract backtrace lines as an array
33 34 35 36 37 38 |
# File 'lib/rails_error_dashboard/services/notification_helpers.rb', line 33 def extract_backtrace(backtrace, limit = 20) return [] if backtrace.nil? lines = backtrace.is_a?(String) ? backtrace.lines : backtrace lines.first(limit).map(&:strip) end |
.extract_first_backtrace_line(backtrace, length = 100) ⇒ String
Extract first backtrace line (truncated)
44 45 46 47 48 49 50 51 52 |
# File 'lib/rails_error_dashboard/services/notification_helpers.rb', line 44 def extract_first_backtrace_line(backtrace, length = 100) return "N/A" if backtrace.nil? lines = backtrace.is_a?(String) ? backtrace.lines : backtrace first_line = lines.first&.strip return "N/A" if first_line.nil? first_line.length > length ? "#{first_line[0...length]}..." : first_line end |
.format_time(time) ⇒ String
Format time for display
69 70 71 72 |
# File 'lib/rails_error_dashboard/services/notification_helpers.rb', line 69 def format_time(time) return "N/A" if time.nil? time.strftime("%Y-%m-%d %H:%M:%S UTC") end |
.parse_request_params(params_json) ⇒ Hash
Parse request params JSON safely
77 78 79 80 81 82 |
# File 'lib/rails_error_dashboard/services/notification_helpers.rb', line 77 def parse_request_params(params_json) return {} if params_json.nil? JSON.parse(params_json) rescue JSON::ParserError {} end |
.platform_emoji(platform) ⇒ String
Platform emoji for Slack/text notifications
57 58 59 60 61 62 63 64 |
# File 'lib/rails_error_dashboard/services/notification_helpers.rb', line 57 def platform_emoji(platform) case platform&.downcase when "ios" then "📱" when "android" then "🤖" when "api" then "🔌" else "💻" end end |
.truncate_message(message, length = 500) ⇒ String
Truncate a message to a maximum length
24 25 26 27 |
# File 'lib/rails_error_dashboard/services/notification_helpers.rb', line 24 def (, length = 500) return "" unless .length > length ? "#{[0...length]}..." : end |