Sha256: 9b8fbcbf8a61bd9b6215f07c6d01d27af29743e8ed86224fa4242eae0a5b07f0

Contents?: true

Size: 958 Bytes

Versions: 19

Compression:

Stored size: 958 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 < Rectify::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 wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if form.invalid?

        closure.update!(signed_at: 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

19 entries across 19 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.9 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.8 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.7 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.5 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.4 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.3 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.2 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.1 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.0 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.25.2 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.25.1 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.25.0 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/votings/sign_polling_station_closure.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/votings/sign_polling_station_closure.rb