Class: Spotlight::AddUploadsFromCsv

Inherits:
ApplicationJob show all
Includes:
JobTracking
Defined in:
app/jobs/spotlight/add_uploads_from_csv.rb

Overview

Process a CSV upload into new Spotlight::Resource::Upload objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JobTracking

#finalize_job_tracker!, #initialize_job_tracker!, #job_tracker, #mark_job_as_failed!

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



10
11
12
# File 'app/jobs/spotlight/add_uploads_from_csv.rb', line 10

def count
  @count
end

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'app/jobs/spotlight/add_uploads_from_csv.rb', line 11

def errors
  @errors
end

Instance Method Details

#perform(csv_data, exhibit, _user) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/jobs/spotlight/add_uploads_from_csv.rb', line 24

def perform(csv_data, exhibit, _user)
  @count = 0
  @errors = {}

  resources(csv_data, exhibit).each_with_index do |resource, index|
    if resource.save_and_index
      @count += 1
    else
      @errors[index + 1] = resource.errors.full_messages + resource.upload&.errors&.full_messages
    end
  end
end