Class: RailsErrorDashboard::Commands::BatchDeleteErrors

Inherits:
Object
  • Object
show all
Includes:
Translation
Defined in:
lib/rails_error_dashboard/commands/batch_delete_errors.rb

Overview

Command: Delete multiple errors at once This is a write operation that destroys multiple ErrorLog records

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Translation

#red_locale, #red_t, #red_tp

Constructor Details

#initialize(error_ids) ⇒ BatchDeleteErrors

Returns a new instance of BatchDeleteErrors.



14
15
16
# File 'lib/rails_error_dashboard/commands/batch_delete_errors.rb', line 14

def initialize(error_ids)
  @error_ids = Array(error_ids).compact
end

Class Method Details

.call(error_ids) ⇒ Object



10
11
12
# File 'lib/rails_error_dashboard/commands/batch_delete_errors.rb', line 10

def self.call(error_ids)
  new(error_ids).call
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails_error_dashboard/commands/batch_delete_errors.rb', line 18

def call
  return { success: false, count: 0, errors: [ red_t("red.commands.no_error_ids") ] } if @error_ids.empty?

  errors = ErrorLog.where(id: @error_ids)
  count = errors.count
  error_ids_to_delete = errors.pluck(:id)

  errors.destroy_all

  # Dispatch plugin event for batch deleted errors
  PluginRegistry.dispatch(:on_errors_batch_deleted, error_ids_to_delete) if error_ids_to_delete.any?

  {
    success: true,
    count: count,
    total: @error_ids.size,
    errors: []
  }
rescue => e
  RailsErrorDashboard::Logger.error("Batch delete failed: #{e.message}")
  { success: false, count: 0, total: @error_ids.size, errors: [ e.message ] }
end