Class: Decidim::Elections::Admin::DestroyElection

Inherits:
Rectify::Command
  • Object
show all
Includes:
AttachmentMethods, GalleryMethods
Defined in:
decidim-elections/app/commands/decidim/elections/admin/destroy_election.rb

Overview

This command is executed when the user destroys an Election from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(election, current_user) ⇒ DestroyElection

Returns a new instance of DestroyElection.


12
13
14
15
16
# File 'decidim-elections/app/commands/decidim/elections/admin/destroy_election.rb', line 12

def initialize(election, current_user)
  @election = election
  @current_user = current_user
  @attached_to = election
end

Instance Method Details

#callObject

Destroys the election if valid.

Broadcasts :ok if successful, :invalid otherwise.


21
22
23
24
25
26
27
# File 'decidim-elections/app/commands/decidim/elections/admin/destroy_election.rb', line 21

def call
  return broadcast(:invalid) if invalid?

  destroy_election!

  broadcast(:ok, election)
end