Sha256: 6611fdf09ae2e6b83e649183ff545211cc292b9af1110f0e47a89885048778f6

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when updating a scope type.
    class UpdateScopeType < Decidim::Command
      # Public: Initializes the command.
      #
      # scope_type - The ScopeType to update
      # form - A form object with the params.
      def initialize(scope_type, form, user)
        @scope_type = scope_type
        @form = form
        @user = user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form was not valid and we could not proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if form.invalid?

        update_scope_type
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_scope_type
        Decidim.traceability.update!(
          @scope_type,
          @user,
          attributes
        )
      end

      def attributes
        {
          name: form.name,
          plural: form.plural
        }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-admin-0.28.5 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.28.4 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.28.3 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.28.2 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.28.1 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.28.0 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/update_scope_type.rb