Sha256: 03c81417d0572518ae1ab8e3d7abf8cb783a099bfd0d5b8a1d9759a3bb4825e7

Contents?: true

Size: 932 Bytes

Versions: 9

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module DecidimAwesome
    class CreateEditorImage < Command
      # Creates a blueprint.
      #
      # form - The form with the data.
      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?

        transaction do
          create_editor_image!
        end

        broadcast(:ok, @editor_image)
      end

      private

      def create_editor_image!
        @editor_image = EditorImage.create!(
          path: form.path,
          decidim_author_id: form.current_user.id,
          organization: form.organization,
          file: form.file
        )
      end

      attr_reader :form
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-decidim_awesome-0.11.3 app/commands/decidim/decidim_awesome/create_editor_image.rb
decidim-decidim_awesome-0.10.3 app/commands/decidim/decidim_awesome/create_editor_image.rb
decidim-decidim_awesome-0.11.2 app/commands/decidim/decidim_awesome/create_editor_image.rb
decidim-decidim_awesome-0.11.1 app/commands/decidim/decidim_awesome/create_editor_image.rb
decidim-decidim_awesome-0.10.2 app/commands/decidim/decidim_awesome/create_editor_image.rb
decidim-decidim_awesome-0.10.1 app/commands/decidim/decidim_awesome/create_editor_image.rb
decidim-decidim_awesome-0.10.0 app/commands/decidim/decidim_awesome/create_editor_image.rb
decidim-decidim_awesome-0.9.3 app/commands/decidim/decidim_awesome/create_editor_image.rb
decidim-decidim_awesome-0.9.1 app/commands/decidim/decidim_awesome/create_editor_image.rb