lib/loaders/csv_loader.rb in datashift-0.40.0 vs lib/loaders/csv_loader.rb in datashift-0.40.1

- old
+ new

@@ -48,49 +48,52 @@ # maps list of headers into suitable calls on the Active Record class bind_headers(headers) begin - puts 'Dummy Run - Changes will be rolled back' if(configuration.dummy_run) + puts 'Dummy Run - Changes will be rolled back' if(DataShift::Configuration.call.dummy_run) load_object_class.transaction do logger.info "Processing #{parsed_file.size} rows" parsed_file.each_with_index do |row, i| - current_row_idx = i logger.info "Processing Row #{i} : #{row}" # Iterate over the bindings, creating a context from data in associated Excel column @binder.bindings.each_with_index do |method_binding, i| + unless method_binding.valid? - logger.warn("No binding was found for column (#{i})") + logger.warn("No binding was found for column (#{i}) [#{method_binding.pp}]") next end - value = row[method_binding.inbound_index] # binding contains column number + # If binding to a column, get the value from the cell (bindings can be to internal methods) + value = method_binding.index ? row[method_binding.index] : nil context = doc_context.create_node_context(method_binding, i, value) - logger.info "Processing Column #{method_binding.inbound_index} (#{method_binding.pp})" + logger.info "Processing Column #{method_binding.index} (#{method_binding.pp})" begin context.process rescue => x if doc_context.all_or_nothing? - logger.error('All or nothing set and Current Columnfailed so complete Row aborted') + logger.error('Complete Row aborted - All or nothing set and Current Column failed.') + logger.error(x.backtrace.first.inspect) + logger.error(x.inspect) break end end end # end of each column(node) doc_context.save_and_monitor_progress doc_context.reset unless doc_context.node_context.next_update? end # all rows processed - if(configuration.dummy_run) + if(DataShift::Configuration.call.dummy_run) puts 'CSV loading stage done - Dummy run so Rolling Back.' raise ActiveRecord::Rollback # Don't actually create/upload to DB if we are doing dummy run end end # TRANSACTION N.B ActiveRecord::Rollback does not propagate outside of the containing transaction block