Class: RailsErrorDashboard::Plugin
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Plugin
- Defined in:
- lib/rails_error_dashboard/plugin.rb
Overview
Base class for creating plugins Plugins can hook into error lifecycle events and extend functionality
Example plugin:
class MyNotificationPlugin < RailsErrorDashboard::Plugin
def name
"My Custom Notifier"
end
def on_error_logged(error_log)
# Send notification to custom service
MyService.notify(error_log)
end
end
# Register the plugin
RailsErrorDashboard.register_plugin(MyNotificationPlugin.new)
Direct Known Subclasses
RailsErrorDashboard::Plugins::AuditLogPlugin, RailsErrorDashboard::Plugins::JiraIntegrationPlugin, RailsErrorDashboard::Plugins::MetricsPlugin
Instance Method Summary collapse
-
#description ⇒ Object
Plugin description (optional).
-
#enabled? ⇒ Boolean
Helper method to check if plugin is enabled Override this to add conditional logic.
-
#name ⇒ Object
Plugin name (must be implemented by subclass).
-
#on_error_logged(error_log) ⇒ Object
Called when a new error is logged (first occurrence).
-
#on_error_recurred(error_log) ⇒ Object
Called when an existing error recurs (subsequent occurrences).
-
#on_error_resolved(error_log) ⇒ Object
Called when an error is resolved.
-
#on_error_viewed(error_log) ⇒ Object
Called when an error is viewed in the dashboard.
-
#on_errors_batch_deleted(error_ids) ⇒ Object
Called when errors are batch deleted.
-
#on_errors_batch_resolved(error_logs) ⇒ Object
Called when errors are batch resolved.
-
#on_register ⇒ Object
Called when plugin is registered Use this for initialization logic.
-
#safe_execute(method_name, *args) ⇒ Object
Helper method to safely execute plugin hooks CRITICAL: Prevents plugin errors from breaking the main application.
-
#version ⇒ Object
Plugin version (optional).
Instance Method Details
#description ⇒ Object
Plugin description (optional)
30 31 32 |
# File 'lib/rails_error_dashboard/plugin.rb', line 30 def description "No description provided" end |
#enabled? ⇒ Boolean
Helper method to check if plugin is enabled Override this to add conditional logic
83 84 85 |
# File 'lib/rails_error_dashboard/plugin.rb', line 83 def enabled? true end |
#name ⇒ Object
Plugin name (must be implemented by subclass)
25 26 27 |
# File 'lib/rails_error_dashboard/plugin.rb', line 25 def name raise NotImplementedError, "Plugin must implement #name" end |
#on_error_logged(error_log) ⇒ Object
Called when a new error is logged (first occurrence)
47 48 49 |
# File 'lib/rails_error_dashboard/plugin.rb', line 47 def on_error_logged(error_log) # Override in subclass to handle event end |
#on_error_recurred(error_log) ⇒ Object
Called when an existing error recurs (subsequent occurrences)
53 54 55 |
# File 'lib/rails_error_dashboard/plugin.rb', line 53 def on_error_recurred(error_log) # Override in subclass to handle event end |
#on_error_resolved(error_log) ⇒ Object
Called when an error is resolved
59 60 61 |
# File 'lib/rails_error_dashboard/plugin.rb', line 59 def on_error_resolved(error_log) # Override in subclass to handle event end |
#on_error_viewed(error_log) ⇒ Object
Called when an error is viewed in the dashboard
77 78 79 |
# File 'lib/rails_error_dashboard/plugin.rb', line 77 def on_error_viewed(error_log) # Override in subclass to handle event end |
#on_errors_batch_deleted(error_ids) ⇒ Object
Called when errors are batch deleted
71 72 73 |
# File 'lib/rails_error_dashboard/plugin.rb', line 71 def on_errors_batch_deleted(error_ids) # Override in subclass to handle event end |
#on_errors_batch_resolved(error_logs) ⇒ Object
Called when errors are batch resolved
65 66 67 |
# File 'lib/rails_error_dashboard/plugin.rb', line 65 def on_errors_batch_resolved(error_logs) # Override in subclass to handle event end |
#on_register ⇒ Object
Called when plugin is registered Use this for initialization logic
41 42 43 |
# File 'lib/rails_error_dashboard/plugin.rb', line 41 def on_register # Override in subclass if needed end |
#safe_execute(method_name, *args) ⇒ Object
Helper method to safely execute plugin hooks CRITICAL: Prevents plugin errors from breaking the main application
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rails_error_dashboard/plugin.rb', line 89 def safe_execute(method_name, *args) return unless enabled? send(method_name, *args) rescue => e # Log plugin failures but never propagate - plugins must not break the app RailsErrorDashboard::Logger.error("[RailsErrorDashboard] Plugin '#{name}' failed in #{method_name}: #{e.class} - #{e.}") RailsErrorDashboard::Logger.error("Plugin version: #{version}") RailsErrorDashboard::Logger.error(e.backtrace&.first(10)&.join("\n")) if e.backtrace nil # Explicitly return nil, never raise end |
#version ⇒ Object
Plugin version (optional)
35 36 37 |
# File 'lib/rails_error_dashboard/plugin.rb', line 35 def version "1.0.0" end |