Sha256: df6507bfef561d2868a132ab8e88b6115eb98b343bd5eb2af25576b8298df891

Contents?: true

Size: 1.29 KB

Versions: 22

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when creating a new participatory
    # process in the system.
    class UpdateParticipatoryProcessStep < Rectify::Command
      attr_reader :participatory_process_step
      # Public: Initializes the command.
      #
      # participatory_process_step - the ParticipatoryProcessStep to update
      # form - A form object with the params.
      def initialize(participatory_process_step, form)
        @participatory_process_step = participatory_process_step
        @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?

        update_participatory_process_step
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_participatory_process_step
        participatory_process_step.update_attributes!(attributes)
      end

      def attributes
        {
          title: form.title,
          start_date: form.start_date,
          end_date: form.end_date,
          description: form.description
        }
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
decidim-admin-0.2.0 app/commands/decidim/admin/update_participatory_process_step.rb
decidim-0.2.0 decidim-admin/app/commands/decidim/admin/update_participatory_process_step.rb