Class: ValidationManager

Inherits:
ImportManager show all
Defined in:
lib/import_manager/validation_manager.rb

Overview

ValidateManager doesn’t import anything. It is used for collecting invalid data to show it in the import table interface.

Instance Attribute Summary

Attributes inherited from ImportManager

#conflict_strategy

Instance Method Summary collapse

Methods inherited from ImportManager

#add_extra_data, #extra_data, #handle_import, #import, #import_card, #import_rows, #initialize

Methods included from ImportManager::Conflicts

#check_for_duplicates, #duplicate, #handle_conflict, #override?, #with_conflict_resolution, #with_conflict_strategy

Methods included from ImportManager::StatusLog

#error_list, #errors, #errors?, #errors_by_row_index, #import_status, #log_status, #pick_up_card_errors, #report, #report_error

Constructor Details

This class inherits a constructor from ImportManager

Instance Method Details

#add_card(args) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/import_manager/validation_manager.rb', line 24

def add_card args
  handle_conflict args[:name], strategy: :skip_card do
    card = Card.new args
    card.validate
    pick_up_card_errors card
  end
end

#each_rowObject



32
33
34
35
# File 'lib/import_manager/validation_manager.rb', line 32

def each_row
  @csv_file.each_row self do |row, i|
  end
end

#row_finished(row) ⇒ Object



37
38
39
# File 'lib/import_manager/validation_manager.rb', line 37

def row_finished row
  @after_validation.call row
end

#validate(row_indices = nil, &block) ⇒ Object



4
5
6
7
# File 'lib/import_manager/validation_manager.rb', line 4

def validate row_indices=nil, &block
  @after_validation = block
  validate_rows row_indices
end

#validate_row(csv_row) ⇒ Object



18
19
20
21
22
# File 'lib/import_manager/validation_manager.rb', line 18

def validate_row csv_row
  handle_import csv_row do
    csv_row.prepare_import
  end
end

#validate_rows(row_indices) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/import_manager/validation_manager.rb', line 9

def validate_rows row_indices
  row_count = row_indices ? row_indices.size : @csv_file.row_count
  @import_status = Status.new counts: { total: row_count }

  @csv_file.each_row self, row_indices do |csv_row|
    validate_row csv_row
  end
end