Sha256: 2a8eef4685b9e50a63e68f074a1be80bd841a8e850491e900614f3519c7b2f29

Contents?: true

Size: 856 Bytes

Versions: 6

Compression:

Stored size: 856 Bytes

Contents

class Topographer::Importer::Strategy::UpdateRecord < Topographer::Importer::Strategy::Base

  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

  def success_message
    'Updated'
  end

  def failure_message
    'Unable to update from import'
  end

end


Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
topographer-0.0.7 lib/topographer/importer/strategy/update_record.rb
topographer-0.0.6 lib/topographer/importer/strategy/update_record.rb
topographer-0.0.5 lib/topographer/importer/strategy/update_record.rb
topographer-0.0.4 lib/topographer/importer/strategy/update_record.rb
topographer-0.0.3 lib/Topographer/importer/strategy/update_record.rb
topographer-0.0.2 lib/Topographer/importer/strategy/update_record.rb