Sha256: 04b80f519983eed6e3aeb46eb4f09b3814cc9518a35b081fa2a4cd9d663268cf

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Decidim
  module Assemblies
    module Admin
      # A command with all the business logic when creating a new assembly
      # type in the system.
      class CreateAssembliesType < Decidim::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.
        # - :invalid if the form was not valid and we could not proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) if form.invalid?

          create_assemblies_type!

          broadcast(:ok)
        end

        private

        attr_reader :form

        def create_assemblies_type!
          Decidim.traceability.create!(
            AssembliesType,
            form.current_user,
            organization: form.current_organization,
            title: form.title
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-assemblies-0.28.4 app/commands/decidim/assemblies/admin/create_assemblies_type.rb
decidim-assemblies-0.28.3 app/commands/decidim/assemblies/admin/create_assemblies_type.rb
decidim-assemblies-0.28.2 app/commands/decidim/assemblies/admin/create_assemblies_type.rb
decidim-assemblies-0.28.1 app/commands/decidim/assemblies/admin/create_assemblies_type.rb
decidim-assemblies-0.28.0 app/commands/decidim/assemblies/admin/create_assemblies_type.rb
decidim-assemblies-0.28.0.rc5 app/commands/decidim/assemblies/admin/create_assemblies_type.rb
decidim-assemblies-0.28.0.rc4 app/commands/decidim/assemblies/admin/create_assemblies_type.rb