Sha256: 23a92e4ada37a06a7b11e9b4cf6980f33a4866a608dabf36dcc36b529122f837

Contents?: true

Size: 950 Bytes

Versions: 7

Compression:

Stored size: 950 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    # A command with all the business logic when signing a closure of a polling station
    class SignPollingStationClosure < Decidim::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      # closure - A closure object.
      def initialize(form, closure)
        @form = form
        @closure = closure
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form was not valid and we could not proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if form.invalid?

        closure.update!(signed_at:, phase: :complete)

        broadcast(:ok)
      end

      private

      attr_reader :form, :closure

      def signed_at
        return unless form.signed

        Time.current
      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/sign_polling_station_closure.rb
decidim-elections-0.28.3 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.28.2 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.28.1 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.28.0 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.28.0.rc5 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.28.0.rc4 app/commands/decidim/votings/sign_polling_station_closure.rb