Class: DataAnon::Strategy::MongoDB::Blacklist

Inherits:
Whitelist show all
Defined in:
lib/strategy/mongodb/blacklist.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 Whitelist

#collection, #dest_collection, #mongo_collection, #source_collection

Methods inherited from Base

#anonymize, #batch_size, #continue, #default_strategy, #dest_table, #initialize, #is_primary_key?, #limit, #primary_key, #process, #process_fields, #process_record_if, #process_table, #process_table_in_batches, #process_table_in_threads, #progress_bar, #progress_bar_class, #skip, #source_table, #source_table_limited, #thread_num, #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)


6
7
8
# File 'lib/strategy/mongodb/blacklist.rb', line 6

def self.whitelist?
  false
end

Instance Method Details

#anonymize_document(document, index, field_strategies = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/strategy/mongodb/blacklist.rb', line 15

def anonymize_document document, index, field_strategies = {}
  field_strategies.each do |field_name, field_strategy|
    field_value = document[field_name]
    unless field_value.nil?
      field = DataAnon::Core::Field.new(field_name, field_value, index, document, @name)
      document[field.name] = AnonymizeField.new(field, field_strategy, self).anonymize
    end
  end
  document
end

#process_record(index, document) ⇒ Object



10
11
12
13
# File 'lib/strategy/mongodb/blacklist.rb', line 10

def process_record index, document
  anonymized_document = anonymize_document(document, index, @fields)
  source_collection.find({'_id' => anonymized_document['_id']}).update_one(anonymized_document)
end