Sha256: ac85a3b57e4be8d7a62cc7fbec64c8297f14dbc3bb6d620c90d615204ac73921

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "csv"

module Decidim
  module Votings
    module Census
      module Admin
        # 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)
        class UpdateDataset < Decidim::Command
          def initialize(dataset, attributes, user)
            @dataset = dataset
            @attributes = attributes
            @user = user
          end

          # Executes the command. Broadcast this events:
          # - :ok when everything is valid
          # - :invalid when the input wasn't valid and couldn't proceed
          #
          # Returns nothing.
          def call
            return broadcast(:invalid) unless valid?

            update_census_dataset!

            broadcast(:ok)
          end

          attr_reader :dataset, :attributes, :user

          def valid?
            user.present? && dataset.present? && attributes.present?
          end

          def update_census_dataset!
            Decidim.traceability.update!(
              dataset,
              user,
              attributes
            )
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-elections-0.27.9 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.8 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.7 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.6 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.5 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.4 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.3 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.2 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.1 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.0 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.0.rc2 app/commands/decidim/votings/census/admin/update_dataset.rb
decidim-elections-0.27.0.rc1 app/commands/decidim/votings/census/admin/update_dataset.rb