Sha256: 941ab9353ba5646163b0a03141cc72e1a6ec4d68322ea748365efcad9e2ff8ce

Contents?: true

Size: 868 Bytes

Versions: 2

Compression:

Stored size: 868 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
          @feature.destroy!
          run_hooks
        end
      end

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

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
decidim-admin-0.0.1 app/commands/decidim/admin/destroy_feature.rb
decidim-0.0.1 decidim-admin/app/commands/decidim/admin/destroy_feature.rb