Class: Decidim::Votings::CertifyPollingStationClosure

Inherits:
Command
  • Object
show all
Includes:
AttachmentMethods, GalleryMethods
Defined in:
app/commands/decidim/votings/certify_polling_station_closure.rb

Overview

A command with all the business logic when signing a closure of a polling station

Instance Method Summary collapse

Constructor Details

#initialize(form, closure) ⇒ CertifyPollingStationClosure

Public: Initializes the command.

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



13
14
15
16
17
# File 'app/commands/decidim/votings/certify_polling_station_closure.rb', line 13

def initialize(form, closure)
  @form = form
  @closure = closure
  @attached_to = closure
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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/commands/decidim/votings/certify_polling_station_closure.rb', line 25

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

  if process_gallery?
    build_gallery
    return broadcast(:invalid) if gallery_invalid?
  end

  transaction do
    create_gallery if process_gallery?
    closure.update!(phase: :signature)
  end

  broadcast(:ok)
end