Sha256: 8b025ff5f058a0fa901f2e0fd3c9c4c5e077abcbba93030dec60e7aa136bba33

Contents?: true

Size: 1.13 KB

Versions: 65

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic to add an attachment collection
    # to a participatory space.
    class CreateAttachmentCollection < Rectify::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      # collection_for - The ActiveRecord::Base that will hold the collection
      def initialize(form, collection_for)
        @form = form
        @collection_for = collection_for
      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_attachment_collection
        broadcast(:ok)
      end

      private

      attr_reader :form

      def create_attachment_collection
        AttachmentCollection.create!(
          name: form.name,
          weight: form.weight,
          description: form.description,
          collection_for: @collection_for
        )
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
decidim-admin-0.23.6 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.24.2 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.23.5 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.24.1 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.24.0 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.24.0.rc2 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.23.4 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.24.0.rc1 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.23.3 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.23.2 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.23.1 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.23.1.rc1 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.23.0 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.22.0 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.21.0 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.20.1 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.20.0 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.19.1 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.18.1 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.19.0 app/commands/decidim/admin/create_attachment_collection.rb