Sha256: a77fed8d0e080d931f15d2061866d46aa63971684bb53bab73267b71d7a839d2

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

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
        include TermCustomizer::PluralFormsForm

        # 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_plural_forms(form.translations)
          destroy_translations

          broadcast(:ok)
        end

        private

        attr_reader :form

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-term_customizer-0.23.0 app/commands/decidim/term_customizer/admin/destroy_translations.rb
decidim-term_customizer-0.22.0 app/commands/decidim/term_customizer/admin/destroy_translations.rb
decidim-term_customizer-0.21.0 app/commands/decidim/term_customizer/admin/destroy_translations.rb
decidim-term_customizer-0.20.0 app/commands/decidim/term_customizer/admin/destroy_translations.rb
decidim-term_customizer-0.19.1 app/commands/decidim/term_customizer/admin/destroy_translations.rb
decidim-term_customizer-0.19.0 app/commands/decidim/term_customizer/admin/destroy_translations.rb
decidim-term_customizer-0.18.0 app/commands/decidim/term_customizer/admin/destroy_translations.rb