Class: Decidim::Notify::UpdateChapter

Inherits:
Admin::UpdateChapter
  • Object
show all
Defined in:
app/commands/decidim/notify/update_chapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ UpdateChapter

Public: Initializes the command.

form - A config form



9
10
11
# File 'app/commands/decidim/notify/update_chapter.rb', line 9

def initialize(form)
  @form = form
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if we couldn’t proceed.

Returns nothing.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/commands/decidim/notify/update_chapter.rb', line 19

def call
  return broadcast(:invalid) if form.invalid?

  begin
    @chapter = Chapter.find(form.id)

    unset_actives
    update_chapter!

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