Class: DumpCleaner::Cleanup::Cleaning

Inherits:
Object
  • Object
show all
Includes:
Uniqueness
Defined in:
lib/dump_cleaner/cleanup/cleaning.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Uniqueness

#repeat_until_unique

Constructor Details

#initialize(config:) ⇒ Cleaning

Returns a new instance of Cleaning.



10
11
12
13
14
# File 'lib/dump_cleaner/cleanup/cleaning.rb', line 10

def initialize(config:)
  @cleaning_workflow = Workflow.new(phase: :cleaning)
  @failure_workflow = Workflow.new(phase: :failure)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/dump_cleaner/cleanup/cleaning.rb', line 8

def config
  @config
end

Instance Method Details

#clean_value_for(orig_value, type:, cleanup_data:, column_config:, record: {}, keep_record: false) ⇒ Object

rubocop:disable Metrics/ParameterLists



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dump_cleaner/cleanup/cleaning.rb', line 16

def clean_value_for(orig_value, type:, cleanup_data:, column_config:, record: {}, keep_record: false) # rubocop:disable Metrics/ParameterLists
  step_context = StepContext.new(orig_value:, type:, cleanup_data:, record:)

  # return orig_value if keep_same conditions are met
  if (keep_record && !config.ignore_keep_same_record_conditions?(type)) ||
     Conditions.evaluate_to_true_in_step?(conditions: config.keep_same_conditions(type), step_context:)
    return orig_value_with_optional_suffix(step_context, column_config:)
  end

  if column_config.unique_column?
    begin
      repeat_until_unique(step_context:) do |repetition|
        step_context.repetition = repetition
        run_workflows(step_context)
      end
    rescue MaxRetriesReachedError
      repeat_until_unique(step_context:) do |repetition|
        step_context.repetition = repetition
        run_failure_workflow(step_context)
      end
    end
  else
    run_workflows(step_context)
  end
end