Sha256: 8824d0edb7d5a4c147551f68dc0dd273a92ebf04fb832719771fb3cb8bb4b6da

Contents?: true

Size: 916 Bytes

Versions: 1

Compression:

Stored size: 916 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    module Admin
      class CreatePonderation < Decidim::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_ponderation

          broadcast(:ok, ponderation)
        end

        private

        attr_reader :form, :ponderation

        def create_ponderation
          @ponderation = Ponderation.create!(name: form.name, weight: form.weight, setting: form.setting)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-action_delegator-0.8.1 app/commands/decidim/action_delegator/admin/create_ponderation.rb