Sha256: b2d09c5c0dd77afe7cf2e271bd78f15da503001dbf4f7f950dddb101191e40d7

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  module Plans
    module Admin
      # A command with all the business logic when a user updates a tag.
      class UpdateTag < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        # tag - The target object to be updated.
        def initialize(form, tag)
          @form = form
          @tag = tag
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid, together with the plan.
        # - :invalid if the form wasn't valid and we couldn't proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) if form.invalid?

          update_tag

          broadcast(:ok, tag)
        end

        private

        attr_reader :form, :tag

        def update_tag
          Decidim.traceability.perform_action!(
            :update,
            tag,
            form.current_user
          ) do
            tag.update!(name: form.name)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-plans-0.18.2 app/commands/decidim/plans/admin/update_tag.rb
decidim-plans-0.18.1 app/commands/decidim/plans/admin/update_tag.rb
decidim-plans-0.18.0 app/commands/decidim/plans/admin/update_tag.rb
decidim-plans-0.17.0 app/commands/decidim/plans/admin/update_tag.rb
decidim-plans-0.16.9 app/commands/decidim/plans/admin/update_tag.rb
decidim-plans-0.16.8 app/commands/decidim/plans/admin/update_tag.rb
decidim-plans-0.16.7 app/commands/decidim/plans/admin/update_tag.rb