Class: SolidusImporter::ProcessImport
- Inherits:
-
Object
- Object
- SolidusImporter::ProcessImport
- Defined in:
- lib/solidus_importer/process_import.rb
Overview
This class parse the source file and create the rows (scan). Then it asks to Process Row to process each one.
Instance Attribute Summary collapse
-
#importer ⇒ Object
readonly
Returns the value of attribute importer.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(import, importer_options: nil) ⇒ ProcessImport
constructor
A new instance of ProcessImport.
- #process(force_scan: nil) ⇒ Object
Constructor Details
#initialize(import, importer_options: nil) ⇒ ProcessImport
Returns a new instance of ProcessImport.
12 13 14 15 16 17 18 |
# File 'lib/solidus_importer/process_import.rb', line 12 def initialize(import, importer_options: nil) @import = import = || ::SolidusImporter::Config.solidus_importer[@import.import_type.to_sym] @importer = [:importer].new() @import.importer = @importer validate! end |
Instance Attribute Details
#importer ⇒ Object (readonly)
Returns the value of attribute importer.
10 11 12 |
# File 'lib/solidus_importer/process_import.rb', line 10 def importer @importer end |
Class Method Details
.import_from_file(import_path, import_type) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/solidus_importer/process_import.rb', line 39 def import_from_file(import_path, import_type) import = ::SolidusImporter::Import.new(import_type: import_type) import.import_file = import_path import.save! new(import).process end |
Instance Method Details
#process(force_scan: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/solidus_importer/process_import.rb', line 20 def process(force_scan: nil) return @import unless @import.created_or_failed? scan_required = force_scan.nil? ? @import.created? : force_scan @import.update(state: :processing) initial_context = scan_required ? scan : { success: true } initial_context = @importer.before_import(initial_context) unless @import.failed? rows = process_rows(initial_context) ending_context = @importer.after_import(initial_context) state = @import.state state = :completed if rows.zero? state = :failed if ending_context[:success] == false @import.update(state: state) end @import end |