Class: Topographer::Importer::Strategy::UpdateRecord
- Inherits:
-
Base
- Object
- Base
- Topographer::Importer::Strategy::UpdateRecord
show all
- Defined in:
- lib/topographer/importer/strategy/update_record.rb
Instance Attribute Summary
Attributes inherited from Base
#dry_run, #mapper
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #should_persist_import?
Instance Method Details
#failure_message ⇒ Object
27
28
29
|
# File 'lib/topographer/importer/strategy/update_record.rb', line 27
def failure_message
'Unable to update from import'
end
|
#import_record(source_data) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/topographer/importer/strategy/update_record.rb', line 3
def import_record (source_data)
mapping_result = mapper.map_input(source_data)
search_params = mapping_result.data.slice(*mapper.key_fields)
model_instance = mapper.model_class.where(search_params).first
if model_instance
model_instance.attributes = mapping_result.data
model_instance.valid?
model_errors = model_instance.errors.full_messages
status = get_import_status(mapping_result, model_errors)
model_instance.save if should_persist_import?(status)
else
status = get_import_status(mapping_result, ["Record not found with params: #{search_params.to_yaml}"])
end
status
end
|
#success_message ⇒ Object
23
24
25
|
# File 'lib/topographer/importer/strategy/update_record.rb', line 23
def success_message
'Updated'
end
|