Sha256: 5db12eb62d520cc366d1d422bf09a365c4b3f715d7a826e2963ca73e1522ac3d

Contents?: true

Size: 1.05 KB

Versions: 36

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when creating a static scope.
    class CreateScope < Rectify::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      # parent_scope - A parent scope for the scope to be created
      def initialize(form, parent_scope = nil)
        @form = form
        @parent_scope = parent_scope
      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_scope
        broadcast(:ok)
      end

      private

      attr_reader :form

      def create_scope
        Scope.create!(
          name: form.name,
          organization: form.organization,
          code: form.code,
          scope_type: form.scope_type,
          parent: @parent_scope
        )
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
decidim-admin-0.9.3 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.9.2 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.9.1 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.9.0 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.8.4 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.8.3 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.8.2 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.8.1 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.8.0 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.7.4 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.7.3 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.7.2 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.7.1 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.7.0 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.6.8 app/commands/decidim/admin/create_scope.rb
decidim-0.6.8 decidim-admin/app/commands/decidim/admin/create_scope.rb
decidim-admin-0.6.7 app/commands/decidim/admin/create_scope.rb
decidim-0.6.7 decidim-admin/app/commands/decidim/admin/create_scope.rb
decidim-admin-0.6.6 app/commands/decidim/admin/create_scope.rb
decidim-0.6.6 decidim-admin/app/commands/decidim/admin/create_scope.rb