Class: DataAnon::Strategy::Whitelist

Inherits:
Base
  • Object
show all
Defined in:
lib/strategy/whitelist.rb

Instance Attribute Summary

Attributes inherited from Base

#errors, #fields, #fields_missing_strategy, #user_strategies

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#anonymize, #batch_size, #default_strategy, #dest_table, #initialize, #is_primary_key?, #primary_key, #process, #process_fields, #process_table, #process_table_in_batches, #progress_bar, #progress_bar_class, #source_table, #whitelist

Methods included from Utils::Logging

#logger, #logger=

Constructor Details

This class inherits a constructor from DataAnon::Strategy::Base

Class Method Details

.whitelist?Boolean

Returns:

  • (Boolean)

5
6
7
# File 'lib/strategy/whitelist.rb', line 5

def self.whitelist?
  true
end

Instance Method Details

#process_record(index, record) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/strategy/whitelist.rb', line 9

def process_record(index, record)
  dest_record_map = {}
  record.attributes.each do |field_name, field_value|
    unless field_value.nil? || is_primary_key?(field_name)
      field = DataAnon::Core::Field.new(field_name, field_value, index, record, @name)
      field_strategy = @fields[field_name.downcase] || default_strategy(field_name)
      dest_record_map[field_name] = field_strategy.anonymize(field)
    end
  end
  dest_record = dest_table.new dest_record_map, without_protection: true
  @primary_keys.each do |key|
    dest_record[key] = record[key]
  end
  dest_record.save!
end