Class: Decidim::Votings::Census::Admin::DestroyDataset

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-elections/app/commands/decidim/votings/census/admin/destroy_dataset.rb

Overview

A command with the business logic to destroy a census dataset from the admin panel.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataset, current_user) ⇒ DestroyDataset

Returns a new instance of DestroyDataset.


12
13
14
15
# File 'decidim-elections/app/commands/decidim/votings/census/admin/destroy_dataset.rb', line 12

def initialize(dataset, current_user)
  @dataset = dataset
  @current_user = current_user
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


30
31
32
# File 'decidim-elections/app/commands/decidim/votings/census/admin/destroy_dataset.rb', line 30

def current_user
  @current_user
end

#datasetObject (readonly)

Returns the value of attribute dataset


30
31
32
# File 'decidim-elections/app/commands/decidim/votings/census/admin/destroy_dataset.rb', line 30

def dataset
  @dataset
end

Instance Method Details

#callObject

Executes the command. Broadcast this events:

  • :ok when everything is valid

  • :invalid when the form wasn't valid and couldn't proceed-

Returns nothing.


22
23
24
25
26
27
28
# File 'decidim-elections/app/commands/decidim/votings/census/admin/destroy_dataset.rb', line 22

def call
  return broadcast(:invalid) unless dataset || current_user

  destroy_census_dataset!

  broadcast(:ok)
end

#destroy_census_dataset!Object


32
33
34
35
36
37
38
39
40
# File 'decidim-elections/app/commands/decidim/votings/census/admin/destroy_dataset.rb', line 32

def destroy_census_dataset!
  Decidim.traceability.perform_action!(
    :delete,
    dataset,
    current_user
  ) do
    dataset.destroy!
  end
end