Class: Decidim::Votings::Admin::MonitoringCommitteeValidatePollingStationClosure

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

Overview

A command with all the business logic for a monitornig committee member to validate a polling station closure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, closure) ⇒ MonitoringCommitteeValidatePollingStationClosure

Public: Initializes the command.

form - A form object with the params. closure - A closure object.


12
13
14
15
# File 'decidim-elections/app/commands/decidim/votings/admin/monitoring_committee_validate_polling_station_closure.rb', line 12

def initialize(form, closure)
  @form = form
  @closure = closure
end

Instance Attribute Details

#closureObject (readonly)

Returns the value of attribute closure


33
34
35
# File 'decidim-elections/app/commands/decidim/votings/admin/monitoring_committee_validate_polling_station_closure.rb', line 33

def closure
  @closure
end

#formObject (readonly)

Returns the value of attribute form


33
34
35
# File 'decidim-elections/app/commands/decidim/votings/admin/monitoring_committee_validate_polling_station_closure.rb', line 33

def form
  @form
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form wasn't valid and we couldn't proceed.

Returns nothing.


23
24
25
26
27
28
29
30
31
# File 'decidim-elections/app/commands/decidim/votings/admin/monitoring_committee_validate_polling_station_closure.rb', line 23

def call
  return broadcast(:invalid) if form.invalid?

  closure.update!(validated_at: Time.current, monitoring_committee_notes: form.monitoring_committee_notes)

  broadcast(:ok)
rescue ActiveRecord::RecordInvalid
  broadcast(:invalid)
end