Class: Decidim::Notify::DeleteChapter

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/notify/delete_chapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ DeleteChapter

Public: Initializes the command.



8
9
10
# File 'app/commands/decidim/notify/delete_chapter.rb', line 8

def initialize(id)
  @id = id
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if we couldn’t proceed.

Returns nothing.



18
19
20
21
22
23
24
25
# File 'app/commands/decidim/notify/delete_chapter.rb', line 18

def call
  chapter = Chapter.for(current_component).find(@id)
  chapter.destroy!

  broadcast(:ok)
rescue ActiveRecord::ActiveRecordError => e
  broadcast(:invalid, e.message)
end