Sha256: 0810f9b887ed98992fc8d6ffdc53e0d0579cad2198f086407c859fa0afbf2e54

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Calagator
  module DuplicateChecking
    module ControllerActions
      # GET /#{model_class}/duplicates
      def duplicates
        @type = params[:type] || "na"
        @grouped = model_class.find_duplicates_by_type(@type)
      rescue ArgumentError => e
        @grouped = {}
        flash[:failure] = e.to_s
      end

      # POST /#{model_class}/squash_multiple_duplicates
      def squash_many_duplicates
        primary = model_class.find_by(id: params[:primary_id])
        duplicate_ids = params.keys.grep(/^duplicate_id_\d+$/) { |t| params[t].to_i }
        duplicates = model_class.where(id: duplicate_ids)

        squasher = model_class.squash(primary, duplicates)
        if squasher.success
          flash[:success] = squasher.success
        else
          flash[:failure] = squasher.failure
        end
        redirect_to action: "duplicates", type: params[:type]
      end

      private

      def model_class
        # Derive model class from controller name
        "Calagator::#{controller_name.singularize.titleize}".constantize
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
koalagator-3.0.0 lib/calagator/duplicate_checking/controller_actions.rb
koalagator-2.1.1 lib/calagator/duplicate_checking/controller_actions.rb
koalagator-2.1.0 lib/calagator/duplicate_checking/controller_actions.rb
calagator2-2.1.1 lib/calagator/duplicate_checking/controller_actions.rb
calagator2-2.1.0 lib/calagator/duplicate_checking/controller_actions.rb