Sha256: 9fe3d28f3b5cc2b15362f9567ee2ba2c58bb29909d06e0cf121bc6f21ce9c9a9

Contents?: true

Size: 1.21 KB

Versions: 19

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module Census
      module Admin
        # A command with the business logic to create increment the dataset
        # processed rows and change the state when the last is processed
        class IncrementDatasetProcessedRows < Rectify::Command
          def initialize(dataset)
            @dataset = dataset
          end

          # Executes the command. Broadcast this events:
          # - :ok when everything is valid
          # - :invalid when the form wasn't valid and couldn't proceed-
          #
          # Returns nothing.
          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

          attr_accessor :dataset

          def all_rows_processed?
            dataset.reload
            return unless dataset.creating_data?

            dataset.csv_row_raw_count == dataset.csv_row_processed_count
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.9 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.8 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.7 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.5 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.4 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.3 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.2 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.1 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.0 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.25.2 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.25.1 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.25.0 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb