Class: Workarea::DataFile::Import
Instance Method Summary
collapse
Methods included from Operation
#complete?, #file_type, #format, #mime_type, #model_class, #name, #sample_file_content, #samples, #tempfile
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
#embedded_children
Instance Method Details
#error? ⇒ Boolean
33
34
35
|
# File 'app/models/workarea/data_file/import.rb', line 33
def error?
error_message.present?
end
|
#failed ⇒ Object
37
38
39
|
# File 'app/models/workarea/data_file/import.rb', line 37
def failed
total - succeeded
end
|
#failure? ⇒ Boolean
29
30
31
|
# File 'app/models/workarea/data_file/import.rb', line 29
def failure?
!successful?
end
|
#file_name ⇒ Object
21
22
23
|
# File 'app/models/workarea/data_file/import.rb', line 21
def file_name
super.presence || file_type&.upcase
end
|
#log(index, instance) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'app/models/workarea/data_file/import.rb', line 58
def log(index, instance)
self.total += 1
if instance.errors.blank? && instance.persisted?
self.succeeded += 1
else
id = instance.new_record? ? index : instance.id
file_errors[id.to_s] = instance.errors.as_json
end
end
|
#process! ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/models/workarea/data_file/import.rb', line 41
def process!
set(started_at: Time.current)
assert_valid_file_type
Workarea::Release.with_current(release_id) do
run_callbacks(:process) { format.import! }
end
rescue Exception => e
self.error_type = e.class
self.error_message = e.message
raise e
ensure
self.completed_at = Time.current
save!
end
|
#releasable? ⇒ Boolean
69
70
71
72
|
# File 'app/models/workarea/data_file/import.rb', line 69
def releasable?
return false unless model_type.present?
model_class.new.releasable?
end
|
#successful? ⇒ Boolean
25
26
27
|
# File 'app/models/workarea/data_file/import.rb', line 25
def successful?
!error? && total == succeeded
end
|