Class: Decidim::Debates::Admin::CreateDebate

Inherits:
Command
  • Object
show all
Defined in:
decidim-debates/app/commands/decidim/debates/admin/create_debate.rb

Overview

This command is executed when the user creates a Debate from the admin panel.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ CreateDebate

Returns a new instance of CreateDebate.



9
10
11
# File 'decidim-debates/app/commands/decidim/debates/admin/create_debate.rb', line 9

def initialize(form)
  @form = form
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Creates the debate if valid.

Broadcasts :ok if successful, :invalid otherwise.



16
17
18
19
20
21
22
23
24
# File 'decidim-debates/app/commands/decidim/debates/admin/create_debate.rb', line 16

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

  transaction do
    create_debate
    send_notification_to_space_followers
  end
  broadcast(:ok)
end