Module: Kiba::Extend::Mixins::IterativeCleanup::Jobs::CleanedUniq

Defined in:
lib/kiba/extend/mixins/iterative_cleanup/jobs/cleaned_uniq.rb

Overview

Since:

  • 4.0.0

Class Method Summary collapse

Class Method Details

.cleaned_xforms(mod) ⇒ Object

Since:

  • 4.0.0



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/kiba/extend/mixins/iterative_cleanup/jobs/cleaned_uniq.rb', line 56

def cleaned_xforms(mod)
  bind = binding

  Kiba.job_segment do
    job = bind.receiver

    transform Delete::Fields,
      fields: mod.all_collate_fields
    transform Deduplicate::Table,
      field: :clean_fingerprint,
      delete_field: false
    transform Merge::MultiRowLookup,
      lookup: send(mod.base_job_cleaned_job_key),
      keycolumn: :clean_fingerprint,
      fieldmap: job.send(:fieldmap, mod),
      delim: mod.collation_delim
  end
end

.field_mapping(field) ⇒ Object

Since:

  • 4.0.0



81
82
83
84
85
86
87
# File 'lib/kiba/extend/mixins/iterative_cleanup/jobs/cleaned_uniq.rb', line 81

def field_mapping(field)
  if field.to_s.end_with?("s")
    [field, field]
  else
    ["#{field}s".to_sym, field]
  end
end

.fieldmap(mod) ⇒ Object

Since:

  • 4.0.0



75
76
77
78
79
# File 'lib/kiba/extend/mixins/iterative_cleanup/jobs/cleaned_uniq.rb', line 75

def fieldmap(mod)
  mod.all_collate_fields.map do |field|
    field_mapping(field)
  end.to_h
end

.get_lookups(mod) ⇒ Object

Since:

  • 4.0.0



22
23
24
25
# File 'lib/kiba/extend/mixins/iterative_cleanup/jobs/cleaned_uniq.rb', line 22

def get_lookups(mod)
  base = [mod.base_job_cleaned_job_key]
  base.select { |job| Kiba::Extend::Job.output?(job) }
end

.get_xforms(mod) ⇒ Object

Since:

  • 4.0.0



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kiba/extend/mixins/iterative_cleanup/jobs/cleaned_uniq.rb', line 27

def get_xforms(mod)
  base = []
  if mod.respond_to?(:cleaned_uniq_pre_xforms)
    base << mod.cleaned_uniq_pre_xforms
  end

  base << if mod.cleanup_done?
    cleaned_xforms(mod)
  else
    orig_xforms(mod)
  end

  if mod.respond_to?(:cleaned_uniq_post_xforms)
    base << mod.cleaned_uniq_post_xforms
  end
  base
end

.job(mod:) ⇒ Object

Since:

  • 4.0.0



11
12
13
14
15
16
17
18
19
20
# File 'lib/kiba/extend/mixins/iterative_cleanup/jobs/cleaned_uniq.rb', line 11

def job(mod:)
  Kiba::Extend::Jobs::Job.new(
    files: {
      source: mod.base_job_cleaned_job_key,
      destination: mod.cleaned_uniq_job_key,
      lookup: get_lookups(mod)
    },
    transformer: get_xforms(mod)
  )
end

.orig_xforms(mod) ⇒ Object

Since:

  • 4.0.0



45
46
47
48
49
50
51
52
53
54
# File 'lib/kiba/extend/mixins/iterative_cleanup/jobs/cleaned_uniq.rb', line 45

def orig_xforms(mod)
  bind = binding

  Kiba.job_segment do
    transform Rename::Fields,
      fieldmap: bind.receiver.send(:fieldmap, mod)
        .invert
        .reject { |key, val| key == val }
  end
end