Sha256: f58e1102f9c5cfc40611f644b38ceb1d98e5bf72e2337de50160ec1b83b9939f

Contents?: true

Size: 991 Bytes

Versions: 65

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when updating an area type.
    class UpdateAreaType < Rectify::Command
      # Public: Initializes the command.
      #
      # area_type - The AreaType to update
      # form - A form object with the params.
      def initialize(area_type, form)
        @area_type = area_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_area_type
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_area_type
        @area_type.update!(attributes)
      end

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

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.9 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.8 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.7 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.5 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.4 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.3 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.2 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.1 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.0 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.0.rc2 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.26.0.rc1 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.25.2 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.25.1 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.25.0 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.25.0.rc4 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.25.0.rc3 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.25.0.rc2 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.25.0.rc1 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.24.3 app/commands/decidim/admin/update_area_type.rb