Sha256: 6cc9299db793612396dbe4e58e7bf244813fe27b3053d5fc129dbb481f5401a8

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Decidim
  module Slider
    module Admin
      # TODO: Remove when upgrading to Decidim 0.28
      class CreateContentBlock < Rectify::Command
        # Public: Initializes the command.
        #
        # organization - the Organization where the content blocks reside
        # scope - the scope applied to the content blocks
        # manifest_name - the manifest name for the content block created
        # scoped_resource_id - (optional) The id of the resource the content blocks belongs to
        def initialize(organization, scope, manifest_name, scoped_resource_id = nil)
          @organization = organization
          @scope = scope
          @manifest_name = manifest_name
          @scoped_resource_id = scoped_resource_id
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid.
        # - :invalid if the data wasn't valid and we couldn't proceed.
        #
        # Returns nothing.
        def call
          create_content_block
          broadcast(:ok)
          # rescue StandardError
          #   broadcast(:invalid)
        end

        private

        attr_reader :organization, :scope, :scoped_resource_id, :manifest_name

        def create_content_block
          Decidim::ContentBlock.create!(
            organization: organization,
            scope_name: scope,
            scoped_resource_id: scoped_resource_id,
            manifest_name: manifest_name
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-slider-0.0.3 app/commands/decidim/slider/admin/create_content_block.rb
decidim-slider-0.0.2 app/commands/decidim/slider/admin/create_content_block.rb
decidim-slider-0.0.1 app/commands/decidim/slider/admin/create_content_block.rb