Class: Importu::Backends::Middleware::DuplicateManagerProxy Private

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/importu/backends/middleware/duplicate_manager_proxy.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wraps any model-based backend adapter to provide duplicate detection.

Instance Method Summary collapse

Constructor Details

#initialize(backend, finder_fields:) ⇒ DuplicateManagerProxy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DuplicateManagerProxy.



10
11
12
13
# File 'lib/importu/backends/middleware/duplicate_manager_proxy.rb', line 10

def initialize(backend, finder_fields:, **)
  super(backend)
  @manager = Importu::DuplicateManager.new(finder_fields: finder_fields)
end

Instance Method Details

#create(record) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Before passing to the backend for create, make sure the record is not a duplicate by using the finder field information that is available. When creating a new object, we will need to record that object as encountered as soon as it has been given a unique id. Any updates to that record within the same import will be treated as duplicate.



20
21
22
23
24
25
26
27
28
29
# File 'lib/importu/backends/middleware/duplicate_manager_proxy.rb', line 20

def create(record)
  @manager.check_record!(record)

  result, object = super

  # Record the newly created object as encountered
  @manager.check_object!(unique_id(object))

  [result, object]
end

#update(record, object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Before passing to the backend for update, make sure the record is not a duplicate by using the finder field information that is available. Also check the object’s unique identifier to ensure we have not already tried to change the object from a previous record import.



35
36
37
38
39
# File 'lib/importu/backends/middleware/duplicate_manager_proxy.rb', line 35

def update(record, object)
  @manager.check_record!(record)
  @manager.check_object!(unique_id(object))
  super
end