Class: SolidusImporter::ImportJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/solidus_importer/import_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(source, import_type = nil) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
# File 'app/jobs/solidus_importer/import_job.rb', line 9

def perform(source, import_type = nil)
  raise ArgumentError, 'Missing import source' unless source

  if source.is_a?(Integer)
    perform_import_from_model(source)
  elsif source.is_a?(String) && import_type.present?
    perform_import_from_filename(source, import_type)
  else
    raise ArgumentError, "#{source} should be a filename or an Import id"
  end
end

#perform_import_from_filename(filename, import_type) ⇒ Object



26
27
28
# File 'app/jobs/solidus_importer/import_job.rb', line 26

def perform_import_from_filename(filename, import_type)
  ::SolidusImporter::ProcessImport.import_from_file(filename, import_type)
end

#perform_import_from_model(id) ⇒ Object



21
22
23
24
# File 'app/jobs/solidus_importer/import_job.rb', line 21

def perform_import_from_model(id)
  import = ::SolidusImporter::Import.find(id)
  ::SolidusImporter::ProcessImport.new(import).process
end