Class: Decidim::Votings::Census::Admin::DestroyDataset
- Inherits:
-
Command
- Object
- Command
- Decidim::Votings::Census::Admin::DestroyDataset
- Defined in:
- 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
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
- #destroy_census_dataset! ⇒ Object
-
#initialize(dataset, current_user) ⇒ DestroyDataset
constructor
A new instance of DestroyDataset.
Constructor Details
#initialize(dataset, current_user) ⇒ DestroyDataset
Returns a new instance of DestroyDataset.
12 13 14 15 |
# File '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_user ⇒ Object (readonly)
Returns the value of attribute current_user.
30 31 32 |
# File 'app/commands/decidim/votings/census/admin/destroy_dataset.rb', line 30 def current_user @current_user end |
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
30 31 32 |
# File 'app/commands/decidim/votings/census/admin/destroy_dataset.rb', line 30 def dataset @dataset end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcast this events:
-
:ok when everything is valid
-
:invalid when the form was not valid and could not proceed-
Returns nothing.
22 23 24 25 26 27 28 |
# File '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 '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 |