Sha256: 8d38697e25c9882d1b365b405fe55ea9bcdf8e7e85a30ff75ffd362464c40e22

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    module Admin
      class CreateParticipant < Rectify::Command
        # Public: Initializes the command.
        #
        # form         - A form object with the params.
        def initialize(form)
          @form = form
        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?

          create_participant

          broadcast(:ok, participant)
        end

        private

        attr_reader :form, :participant

        def create_participant
          @participant = Participant.create!(email: form.email,
                                             phone: form.phone,
                                             decidim_action_delegator_ponderation_id: form.decidim_action_delegator_ponderation_id,
                                             setting: form.setting)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-action_delegator-0.7.2 app/commands/decidim/action_delegator/admin/create_participant.rb
decidim-action_delegator-0.7.1 app/commands/decidim/action_delegator/admin/create_participant.rb
decidim-action_delegator-0.7.0 app/commands/decidim/action_delegator/admin/create_participant.rb