Sha256: b3d00f120d68d7bef05a322c2df96f2e03885e8e689d34c84179352f3362e36d

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module TermCustomizer
    module Admin
      # A command with all the business logic when an admin destroys
      # translations from a translation set.
      class DestroyTranslations < 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.
        # - :invalid if the form wasn't valid and we couldn't proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) unless form.valid?

          destroy_translations

          broadcast(:ok)
        end

        private

        attr_reader :form

        def destroy_translations
          form.translations.destroy_all
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-term_customizer-0.17.1 app/commands/decidim/term_customizer/admin/destroy_translations.rb
decidim-term_customizer-0.17.0 app/commands/decidim/term_customizer/admin/destroy_translations.rb