Sha256: 48aec0767245b28fc5791ab7805c4839a428b83a9dfb68c0326d6ba65176d1bf

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Decidim
  module Plans
    module Admin
      # A command with all the business logic when a user creates a new tag.
      class CreateTag < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        def initialize(form)
          @form = form
        end

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

          create_tag

          broadcast(:ok, tag)
        end

        private

        attr_reader :form, :tag

        def create_tag
          @tag = Decidim.traceability.create(
            Tag,
            form.current_user,
            name: form.name,
            organization: form.organization
          )
        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/create_tag.rb
decidim-plans-0.18.1 app/commands/decidim/plans/admin/create_tag.rb
decidim-plans-0.18.0 app/commands/decidim/plans/admin/create_tag.rb
decidim-plans-0.17.0 app/commands/decidim/plans/admin/create_tag.rb
decidim-plans-0.16.9 app/commands/decidim/plans/admin/create_tag.rb
decidim-plans-0.16.8 app/commands/decidim/plans/admin/create_tag.rb
decidim-plans-0.16.7 app/commands/decidim/plans/admin/create_tag.rb