Sha256: 417c3a71b27b43febe7a0c37a40bda840100f0bde3fb057bebd345bf43a0efc9

Contents?: true

Size: 1011 Bytes

Versions: 36

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

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

        update_scope_type
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_scope_type
        @scope_type.update_attributes!(attributes)
      end

      def attributes
        {
          name: form.name,
          plural: form.plural
        }
      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/update_scope_type.rb
decidim-admin-0.9.2 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.9.1 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.9.0 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.8.4 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.8.3 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.8.2 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.8.1 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.8.0 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.7.4 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.7.3 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.7.2 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.7.1 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.7.0 app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.6.8 app/commands/decidim/admin/update_scope_type.rb
decidim-0.6.8 decidim-admin/app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.6.7 app/commands/decidim/admin/update_scope_type.rb
decidim-0.6.7 decidim-admin/app/commands/decidim/admin/update_scope_type.rb
decidim-admin-0.6.6 app/commands/decidim/admin/update_scope_type.rb
decidim-0.6.6 decidim-admin/app/commands/decidim/admin/update_scope_type.rb