Class: Decidim::Votings::Census::Admin::IncrementDatasetProcessedRows

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-elections/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

Instance Method Summary collapse

Constructor Details

#initialize(dataset) ⇒ IncrementDatasetProcessedRows

Returns a new instance of IncrementDatasetProcessedRows.


10
11
12
# File 'decidim-elections/app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb', line 10

def initialize(dataset)
  @dataset = dataset
end

Instance Attribute Details

#datasetObject

Returns the value of attribute dataset


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

def dataset
  @dataset
end

Instance Method Details

#all_rows_processed?Boolean

Returns:

  • (Boolean)

33
34
35
36
37
38
# File 'decidim-elections/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

#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.


19
20
21
22
23
24
25
26
27
28
29
# File 'decidim-elections/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