Class: Import
- Inherits:
-
ApplicationRecord
show all
- Includes:
- ActiveModel::Validations
- Defined in:
- app/models/import.rb,
app/models/import/csv_header_validator.rb,
app/models/import/csv_duplicates_validator.rb
Overview
Defined Under Namespace
Classes: CsvDuplicatesValidator, CsvHeaderValidator
Instance Method Summary
collapse
Instance Method Details
#all_mapping_keys ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'app/models/import.rb', line 54
def all_mapping_keys
database = mappings.collect(&:destination_field)
default = default_mappings.collect(&:keys)
assumed = assumed_mappings.collect(&:values)
mappings = (database + default + assumed).flatten
mappings.map(&:to_s)
end
|
#check_if_mapped ⇒ Object
50
51
52
|
# File 'app/models/import.rb', line 50
def check_if_mapped
state_machine.transition_to!(:mapped) if mappings_valid? && state_machine.can_transition_to?(:mapped)
end
|
#convert_data(extract_hash) ⇒ Object
78
79
80
81
82
83
84
|
# File 'app/models/import.rb', line 78
def convert_data()
converted_data = ()
converted_data = append_default_mappings(converted_data)
converted_data = append_assumed_mappings(converted_data)
converted_data = append_derived_mappings(converted_data)
append_required_mappings(converted_data)
end
|
#mappings_valid? ⇒ Boolean
63
64
65
|
# File 'app/models/import.rb', line 63
def mappings_valid?
(GEOMG_SCHEMA[:required] - all_mapping_keys.uniq).empty?
end
|
#run! ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'app/models/import.rb', line 67
def run!
ImportRunJob.perform_later(self)
state_machine.transition_to!(:imported)
save
end
|
#set_csv_file_attributes ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/models/import.rb', line 38
def set_csv_file_attributes
parsed = CSV.parse(csv_file.download)
update_columns(
headers: parsed[0],
row_count: parsed.size - 1,
content_type: csv_file.content_type.to_s,
filename: csv_file.filename.to_s,
extension: csv_file.filename.extension.to_s
)
end
|