Class: DataTaster::Sanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/data_taster/sanitizer.rb,
sig/data_taster.rbs

Constant Summary collapse

BATCH_SIZE =

Returns:

  • (Integer)
SanitizerExporter::BATCH_SIZE

Instance Method Summary collapse

Constructor Details

#initialize(table_name, custom_selections) ⇒ Sanitizer

Ensures the given tables are cleaned of information deemed sensitive



8
9
10
11
# File 'lib/data_taster/sanitizer.rb', line 8

def initialize(table_name, custom_selections)
  @table_name = table_name
  @custom_selections = custom_selections || {}
end

Instance Method Details

#clean!Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/data_taster/sanitizer.rb', line 13

def clean!
  return if skippable_table?

  # custom selections should ALWAYS override defaults
  default_selections.merge(custom_selections).filter_map do |column_name, sanitized_value|
    sql = DataTaster::Detergent.new(
      table_name, column_name, sanitized_value
    ).deliver

    process(sql)
  end
end

#export_sanitized_rows(collection, insert_table_name:) {|header, values| ... } ⇒ void

This method returns an undefined value.

Parameters:

  • collection (Collection)
  • insert_table_name: (String)

Yields:

Yield Parameters:

  • header (String)
  • values (String)

Yield Returns:

  • (void)


36
37
38
39
# File 'lib/data_taster/sanitizer.rb', line 36

def export_sanitized_rows(collection, insert_table_name:, &write_insert)
  SanitizerExporter.new(table_name, custom_selections, insert_table_name: insert_table_name)
                   .export_sanitized_rows(collection, &write_insert)
end

#sanitization_rulesObject



26
27
28
29
30
31
32
33
34
# File 'lib/data_taster/sanitizer.rb', line 26

def sanitization_rules
  return {} if skippable_table?

  default_selections.merge(custom_selections).each_with_object({}) do |(column_name, sanitized_value), memo|
    next if sanitized_value == DataTaster::SKIP_CODE

    memo[column_name.to_s] = sanitized_value
  end
end