Class: Decidim::Commands::SoftDeleteResource

Inherits:
Decidim::Command show all
Defined in:
decidim-core/lib/decidim/commands/soft_delete_resource.rb

Instance Method Summary collapse

Methods inherited from Decidim::Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(resource, current_user) ⇒ SoftDeleteResource

Initializes the command.

Parameters:

  • resource (ActiveRecord::Base)

    the resource to soft delete.

  • current_user (Decidim::User)

    the current user.



10
11
12
13
# File 'decidim-core/lib/decidim/commands/soft_delete_resource.rb', line 10

def initialize(resource, current_user)
  @resource = resource
  @current_user = current_user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Soft deletes the resource.

Broadcasts :ok if successful, :invalid otherwise.



18
19
20
21
22
23
24
25
26
27
# File 'decidim-core/lib/decidim/commands/soft_delete_resource.rb', line 18

def call
  return broadcast(:invalid) if invalid?

  soft_delete_resource
  send_notification_to_authors

  broadcast(:ok, resource)
rescue Decidim::Commands::HookError, StandardError
  broadcast(:invalid)
end