Class: Importer::Import

Inherits:
Object
  • Object
show all
Defined in:
lib/importer/import.rb

Overview

Summary of import. Contains detailed information about import process, all imported objects, no matter if they were imported successfully or not.

The importer builds it’s Import instance by adding imported objects via add_object.

If you want to have your own implementation of Import summary (f.e. activerecord-based), you can force the importer to use it with:

Product.import(path_to_xml_or_csv_file, :import => CustomImportClass)

Just be sure to implement add_object and build_imported_object methods in your custom class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Import

Returns a new instance of Import.



19
20
21
22
# File 'lib/importer/import.rb', line 19

def initialize(options = nil)
  @imported_objects = []
  @options          = options
end

Instance Attribute Details

#imported_objectsObject (readonly)

Returns the value of attribute imported_objects.



17
18
19
# File 'lib/importer/import.rb', line 17

def imported_objects
  @imported_objects
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/importer/import.rb', line 17

def options
  @options
end

Instance Method Details

#add_object(imported_object) ⇒ Object



24
25
26
# File 'lib/importer/import.rb', line 24

def add_object(imported_object)
  imported_objects << imported_object
end

#build_imported_objectObject



28
29
30
# File 'lib/importer/import.rb', line 28

def build_imported_object
  ImportedObject.new
end

#existing_imported_objectsObject



36
37
38
# File 'lib/importer/import.rb', line 36

def existing_imported_objects
  imported_objects.select { |object| object.state == 'existing_object' }
end

#invalid_imported_objectsObject



40
41
42
# File 'lib/importer/import.rb', line 40

def invalid_imported_objects
  imported_objects.select { |object| object.state == 'invalid_object' }
end

#new_imported_objectsObject



32
33
34
# File 'lib/importer/import.rb', line 32

def new_imported_objects
  imported_objects.select { |object| object.state == 'new_object' }
end