Class: Database::ConsistencyFixService

Inherits:
Object
  • Object
show all
Defined in:
app/services/database/consistency_fix_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_model:, target_model:, sync_event_class:, source_sort_key:, target_sort_key:) ⇒ ConsistencyFixService

Returns a new instance of ConsistencyFixService.



5
6
7
8
9
10
11
# File 'app/services/database/consistency_fix_service.rb', line 5

def initialize(source_model:, target_model:, sync_event_class:, source_sort_key:, target_sort_key:)
  @source_model = source_model
  @target_model = target_model
  @sync_event_class = sync_event_class
  @source_sort_key = source_sort_key
  @target_sort_key = target_sort_key
end

Instance Attribute Details

#source_modelObject

Returns the value of attribute source_model.



13
14
15
# File 'app/services/database/consistency_fix_service.rb', line 13

def source_model
  @source_model
end

#source_sort_keyObject

Returns the value of attribute source_sort_key.



13
14
15
# File 'app/services/database/consistency_fix_service.rb', line 13

def source_sort_key
  @source_sort_key
end

#sync_event_classObject

Returns the value of attribute sync_event_class.



13
14
15
# File 'app/services/database/consistency_fix_service.rb', line 13

def sync_event_class
  @sync_event_class
end

#target_modelObject

Returns the value of attribute target_model.



13
14
15
# File 'app/services/database/consistency_fix_service.rb', line 13

def target_model
  @target_model
end

#target_sort_keyObject

Returns the value of attribute target_sort_key.



13
14
15
# File 'app/services/database/consistency_fix_service.rb', line 13

def target_sort_key
  @target_sort_key
end

Instance Method Details

#execute(ids:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'app/services/database/consistency_fix_service.rb', line 15

def execute(ids:)
  ids.each do |id|
    if source_object(id) && target_object(id)
      create_sync_event_for(id)
    elsif target_object(id)
      target_object(id).destroy!
    end
  end
  sync_event_class.enqueue_worker
end