Class: Decidim::Votings::Census::Admin::IncrementDatasetProcessedRows
- Inherits:
-
Command
- Object
- Command
- Decidim::Votings::Census::Admin::IncrementDatasetProcessedRows
- Defined in:
- app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
Overview
A command with the business logic to create increment the dataset processed rows and change the state when the last is processed
Instance Attribute Summary collapse
-
#dataset ⇒ Object
Returns the value of attribute dataset.
Instance Method Summary collapse
- #all_rows_processed? ⇒ Boolean
-
#call ⇒ Object
Executes the command.
-
#initialize(dataset) ⇒ IncrementDatasetProcessedRows
constructor
A new instance of IncrementDatasetProcessedRows.
Constructor Details
#initialize(dataset) ⇒ IncrementDatasetProcessedRows
Returns a new instance of IncrementDatasetProcessedRows.
10 11 12 |
# File 'app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb', line 10 def initialize(dataset) @dataset = dataset end |
Instance Attribute Details
#dataset ⇒ Object
Returns the value of attribute dataset.
31 32 33 |
# File 'app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb', line 31 def dataset @dataset end |
Instance Method Details
#all_rows_processed? ⇒ Boolean
33 34 35 36 37 38 |
# File 'app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb', line 33 def all_rows_processed? dataset.reload return unless dataset.creating_data? dataset.csv_row_raw_count == dataset.csv_row_processed_count end |
#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.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb', line 19 def call return broadcast(:invalid) unless dataset # rubocop:disable Rails/SkipsModelValidations Dataset.increment_counter(:csv_row_processed_count, dataset.id) # rubocop:enable Rails/SkipsModelValidations dataset.data_created! if all_rows_processed? broadcast(:ok) end |