Class: Decidim::EnhancedTextwork::Admin::DestroyParagraph

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb

Overview

A command with all the business logic when a user destroys a draft paragraph.

Instance Method Summary collapse

Constructor Details

#initialize(paragraph) ⇒ DestroyParagraph

Public: Initializes the command.

paragraph - The paragraph to destroy.



11
12
13
# File 'app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb', line 11

def initialize(paragraph)
  @paragraph = paragraph
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid and the paragraph is deleted.

  • :invalid if the paragraph is not a draft.

  • :invalid if the paragraph's author is not the current user.

Returns nothing.



22
23
24
25
26
27
28
# File 'app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb', line 22

def call
  return broadcast(:invalid) unless @paragraph.draft?

  @paragraph.destroy!

  broadcast(:ok, @paragraph)
end