Class: Decidim::Votings::Census::Admin::UpdateDataset
- Inherits:
-
Command
- Object
- Command
- Decidim::Votings::Census::Admin::UpdateDataset
- Defined in:
- app/commands/decidim/votings/census/admin/update_dataset.rb
Overview
A command with the business logic to update a census dataset.
dataset - the Decidim::Votings::Census::Dataset to update attributes - the hash of attibutes to update user - the user performing the action (used for tracing)
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(dataset, attributes, user) ⇒ UpdateDataset
constructor
A new instance of UpdateDataset.
- #update_census_dataset! ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(dataset, attributes, user) ⇒ UpdateDataset
Returns a new instance of UpdateDataset.
15 16 17 18 19 |
# File 'app/commands/decidim/votings/census/admin/update_dataset.rb', line 15 def initialize(dataset, attributes, user) @dataset = dataset @attributes = attributes @user = user end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
34 35 36 |
# File 'app/commands/decidim/votings/census/admin/update_dataset.rb', line 34 def attributes @attributes end |
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
34 35 36 |
# File 'app/commands/decidim/votings/census/admin/update_dataset.rb', line 34 def dataset @dataset end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
34 35 36 |
# File 'app/commands/decidim/votings/census/admin/update_dataset.rb', line 34 def user @user end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcast this events:
-
:ok when everything is valid
-
:invalid when the input was not valid and could not proceed
Returns nothing.
26 27 28 29 30 31 32 |
# File 'app/commands/decidim/votings/census/admin/update_dataset.rb', line 26 def call return broadcast(:invalid) unless valid? update_census_dataset! broadcast(:ok) end |
#update_census_dataset! ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/commands/decidim/votings/census/admin/update_dataset.rb', line 40 def update_census_dataset! Decidim.traceability.update!( dataset, user, attributes ) end |
#valid? ⇒ Boolean
36 37 38 |
# File 'app/commands/decidim/votings/census/admin/update_dataset.rb', line 36 def valid? user.present? && dataset.present? && attributes.present? end |