Sha256: 58aa5909f549cbca1ef79e49ce6ad8579229958143123ac1cdb76ec29fed4d17
Contents?: true
Size: 1.96 KB
Versions: 30
Compression:
Stored size: 1.96 KB
Contents
module CmAdmin class BulkActionProcessor extend ActiveSupport::Concern attr_accessor :invalid_records, :success_records def initialize(current_action, model, params) @invalid_records = [] @success_records = [] @current_action = current_action @model = model @params = params end def perform_individual_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 @success_records << OpenStruct.new({ row_identifier: ar_object.send(column_name) }) unless @error_message end self end def perform_bulk_action ar_object = @model.ar_model.where(id: @params[:selected_ids]).first column_name = @model.available_fields[:index].first.field_name begin @current_action.code_block.call(@params[:selected_ids]) @error_message = nil rescue NoMethodError, NameError => e @error_message = e.message.to_s rescue ActiveRecord::RecordInvalid => e @error_message = e.message.to_s rescue StandardError => e @error_message = e.message.to_s end @invalid_records << OpenStruct.new({ row_identifier: ar_object.send(column_name), error_message: @error_message }) if @error_message self end end end
Version data entries
30 entries across 30 versions & 1 rubygems