Class: Importr::Importer

Inherits:
ActiveImporter::Base
  • Object
show all
Defined in:
lib/importr/importer.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Importer

Returns a new instance of Importer.



5
6
7
8
9
10
11
12
13
# File 'lib/importr/importer.rb', line 5

def initialize(file, options = {})
  # TODO: ensure that data_import.model_class == self.class.model_class

  super

  if data_import && data_import.finished
    raise "Data import #{data_import.id} was already processed"
  end
end

Instance Method Details

#import_failed(error_message) ⇒ Object



29
30
31
32
# File 'lib/importr/importer.rb', line 29

def import_failed(error_message)
  super
  notify(:base, error: error_message)
end

#import_finishedObject



34
35
36
# File 'lib/importr/importer.rb', line 34

def import_finished
  data_import.update_attribute(:finished, true) if data_import
end

#row_error(error_message) ⇒ Object



23
24
25
26
27
# File 'lib/importr/importer.rb', line 23

def row_error(error_message)
  super
  update_counters
  notify(:error, @counters.merge(index: row_index, error: error_message))
end

#row_successObject



17
18
19
20
21
# File 'lib/importr/importer.rb', line 17

def row_success
  super
  update_counters
  notify(:success, @counters)
end