Class: SolidusImporter::ProcessRow

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_importer/process_row.rb

Overview

This class process a single row of an import running the configured processor in chain.

Instance Method Summary collapse

Constructor Details

#initialize(importer, row) ⇒ ProcessRow

Returns a new instance of ProcessRow.



8
9
10
11
12
# File 'lib/solidus_importer/process_row.rb', line 8

def initialize(importer, row)
  @importer = importer
  @row = row
  validate!
end

Instance Method Details

#process(initial_context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/solidus_importer/process_row.rb', line 14

def process(initial_context)
  context = initial_context.dup.merge!(row_id: @row.id, importer: @importer, data: @row.data)
  @importer.processors.each do |processor|
    begin
      processor.call(context)
    rescue StandardError => e
      context.merge!(success: false, messages: e.message) # rubocop:disable Performance/RedundantMerge
      break
    end
  end

  @importer.handle_row_import(context)

  @row.update!(
    state: context[:success] ? :completed : :failed,
    messages: context[:messages]
  )
  check_import_finished(context)
  context
end