Sha256: 18e6d71c58088e69b221d29e636975fa525374d5a88d4e6872f1ab0fb8247244
Contents?: true
Size: 971 Bytes
Versions: 3
Compression:
Stored size: 971 Bytes
Contents
# frozen_string_literal: true module Decidim module Admin # A command with all the business logic to destroy a category in the # system. class DestroyCategory < Decidim::Command # Public: Initializes the command. # # category - A Category that will be destroyed def initialize(category, user) @category = category @user = user end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if the data was not valid and we could not proceed. # # Returns nothing. def call return broadcast(:invalid) if category.nil? || category.subcategories.any? destroy_category broadcast(:ok) end private attr_reader :category def destroy_category Decidim.traceability.perform_action!(:delete, category, @user) do category.destroy! end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems