Class: RailsErrorDashboard::Plugin

Inherits:
Object
  • Object
show all
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)

Instance Method Summary collapse

Instance Method Details

#descriptionObject

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

Returns:

  • (Boolean)


83
84
85
# File 'lib/rails_error_dashboard/plugin.rb', line 83

def enabled?
  true
end

#nameObject

Plugin name (must be implemented by subclass)

Raises:

  • (NotImplementedError)


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)

Parameters:

  • error_log (ErrorLog)

    The newly created error log



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)

Parameters:

  • error_log (ErrorLog)

    The updated error log



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

Parameters:

  • error_log (ErrorLog)

    The resolved error log



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

Parameters:

  • error_log (ErrorLog)

    The viewed error log



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

Parameters:

  • error_ids (Array<Integer>)

    The IDs of deleted errors



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

Parameters:

  • error_logs (Array<ErrorLog>)

    The resolved error logs



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_registerObject

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.message}")
  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

#versionObject

Plugin version (optional)



35
36
37
# File 'lib/rails_error_dashboard/plugin.rb', line 35

def version
  "1.0.0"
end