Sha256: ba45f50d90bf9a539de37cfdd6c646a8b2caeb5ed03e3e408dcc220b9a0f2ee0

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 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 < Decidim::Command
          def initialize(dataset)
            @dataset = dataset
          end

          # Executes the command. Broadcast this events:
          # - :ok when everything is valid
          # - :invalid when the form was not valid and could not 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

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.28.3 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.28.2 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.28.1 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.28.0 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.28.0.rc5 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb
decidim-elections-0.28.0.rc4 app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb