Sha256: 520856e8ec043f5f062665c05da252a9e428d059152766ed724b1a83b653c1f4

Contents?: true

Size: 1.06 KB

Versions: 88

Compression:

Stored size: 1.06 KB

Contents

class CmAdmin::BulkActionProcessor
  extend ActiveSupport::Concern
  attr_accessor :invalid_records

  def initialize(current_action, model, params)
    @invalid_records = []
    @current_action = current_action
    @model = model
    @params = params
  end

  def perform_bulk_action
    @params[:selected_ids].split(',').each do |id|
      ar_object = @model.ar_model.find(id)
      column_name = @model.available_fields[:index].first.field_name
      begin
        @current_action.code_block.call(id)
        @error_message = nil
      rescue NoMethodError, NameError => e
        @error_message = "#{e.message.slice(0..(e.message.index(' for')))} at #{ar_object.send(column_name)}"
      rescue ActiveRecord::RecordInvalid => e
        @error_message = "#{e.message} at #{ar_object.send(column_name)}"
      rescue StandardError => e
        @error_message = "#{ar_object.send(column_name)} - #{e.message}"
      end
      @invalid_records << OpenStruct.new({ row_identifier: ar_object.send(column_name), error_message: @error_message }) if @error_message
    end
    self
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
cm-admin-2.4.4 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.4.3 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.4.2 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.4.1 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.4.0 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.3.4 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.3.3 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.3.2 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.3.1 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.3.0 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.2.1 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.2.0 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.1.5 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.1.4 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.1.3 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.1.2 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.1.1 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.1.0 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.0.2 app/models/concerns/cm_admin/bulk_action_processor.rb
cm-admin-2.0.1 app/models/concerns/cm_admin/bulk_action_processor.rb