Class: Decidim::Votings::Census::Admin::UpdateDataset

Inherits:
Command
  • Object
show all
Defined in:
decidim-elections/app/commands/decidim/votings/census/admin/update_dataset.rb

Overview

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)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(dataset, attributes, user) ⇒ UpdateDataset

Returns a new instance of UpdateDataset.



15
16
17
18
19
# File 'decidim-elections/app/commands/decidim/votings/census/admin/update_dataset.rb', line 15

def initialize(dataset, attributes, user)
  @dataset = dataset
  @attributes = attributes
  @user = user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



34
35
36
# File 'decidim-elections/app/commands/decidim/votings/census/admin/update_dataset.rb', line 34

def attributes
  @attributes
end

#datasetObject (readonly)

Returns the value of attribute dataset.



34
35
36
# File 'decidim-elections/app/commands/decidim/votings/census/admin/update_dataset.rb', line 34

def dataset
  @dataset
end

#userObject (readonly)

Returns the value of attribute user.



34
35
36
# File 'decidim-elections/app/commands/decidim/votings/census/admin/update_dataset.rb', line 34

def user
  @user
end

Instance Method Details

#callObject

Executes the command. Broadcast this events:

  • :ok when everything is valid

  • :invalid when the input was not valid and could not proceed

Returns nothing.



26
27
28
29
30
31
32
# File 'decidim-elections/app/commands/decidim/votings/census/admin/update_dataset.rb', line 26

def call
  return broadcast(:invalid) unless valid?

  update_census_dataset!

  broadcast(:ok)
end

#update_census_dataset!Object



40
41
42
43
44
45
46
# File 'decidim-elections/app/commands/decidim/votings/census/admin/update_dataset.rb', line 40

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

#valid?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'decidim-elections/app/commands/decidim/votings/census/admin/update_dataset.rb', line 36

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