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.12.0.pre app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.11.1 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.11.0.pre1 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.10.1 app/commands/decidim/admin/update_area_type.rb
decidim-admin-0.10.0 app/commands/decidim/admin/update_area_type.rb