Sha256: 6d531ec900ac271edb1392729ff1179dc9a5310101f204452b2c65384f66a646

Contents?: true

Size: 997 Bytes

Versions: 54

Compression:

Stored size: 997 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This command deals with destroying a Feature from the admin panel.
    class DestroyFeature < Rectify::Command
      # Public: Initializes the command.
      #
      # feature - The Feature to be destroyed.
      def initialize(feature)
        @feature = feature
      end

      # Public: Executes the command.
      #
      # Broadcasts :ok if it got destroyed, raises an exception otherwise.
      def call
        begin
          destroy_feature
        rescue StandardError
          return broadcast(:invalid)
        end
        broadcast(:ok)
      end

      private

      def destroy_feature
        transaction do
          run_before_hooks
          @feature.destroy!
          run_hooks
        end
      end

      def run_before_hooks
        @feature.manifest.run_hooks(:before_destroy, @feature)
      end

      def run_hooks
        @feature.manifest.run_hooks(:destroy, @feature)
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 2 rubygems

Version Path
decidim-admin-0.9.3 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.9.2 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.9.1 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.9.0 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.8.4 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.8.3 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.8.2 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.8.1 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.8.0 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.7.4 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.7.3 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.7.2 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.7.1 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.7.0 app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.6.8 app/commands/decidim/admin/destroy_feature.rb
decidim-0.6.8 decidim-admin/app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.6.7 app/commands/decidim/admin/destroy_feature.rb
decidim-0.6.7 decidim-admin/app/commands/decidim/admin/destroy_feature.rb
decidim-admin-0.6.6 app/commands/decidim/admin/destroy_feature.rb
decidim-0.6.6 decidim-admin/app/commands/decidim/admin/destroy_feature.rb