Class: DataAnon::Core::Database

Inherits:
Object
  • Object
show all
Includes:
Utils::Logging
Defined in:
lib/core/database.rb

Instance Method Summary collapse

Methods included from Utils::Logging

#logger, #logger=

Constructor Details

#initialize(name) ⇒ Database

Returns a new instance of Database.



7
8
9
10
11
12
13
14
15
# File 'lib/core/database.rb', line 7

def initialize name
  @name = name
  @strategy = DataAnon::Strategy::Whitelist
  @user_defaults = {}
  @tables = []
  @execution_strategy = DataAnon::Core::Sequential
  ENV['parallel_execution'] = 'false'
  I18n.enforce_available_locales = false
end

Instance Method Details

#anonymizeObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/core/database.rb', line 44

def anonymize
  begin
    @execution_strategy.new.anonymize @tables
  rescue => e
    logger.error "\n#{e.message} \n #{e.backtrace}"
  end
  if @strategy.whitelist?
    @tables.each do |table|
      if table.fields_missing_strategy.present?
        logger.info('Fields missing the anonymization strategy:')
        table.fields_missing_strategy.print
      end
    end
  end

  @tables.each { |table| table.errors.print }
end

#default_field_strategies(default_strategies) ⇒ Object



34
35
36
# File 'lib/core/database.rb', line 34

def default_field_strategies default_strategies
  @user_defaults = default_strategies
end

#destination_db(connection_spec) ⇒ Object



30
31
32
# File 'lib/core/database.rb', line 30

def destination_db connection_spec
  @destination_database = connection_spec
end

#execution_strategy(execution_strategy) ⇒ Object



21
22
23
24
# File 'lib/core/database.rb', line 21

def execution_strategy execution_strategy
  @execution_strategy = execution_strategy
  ENV['parallel_execution'] = 'true' if execution_strategy == DataAnon::Parallel::Table
end

#source_db(connection_spec) ⇒ Object



26
27
28
# File 'lib/core/database.rb', line 26

def source_db connection_spec
  @source_database = connection_spec
end

#strategy(strategy) ⇒ Object



17
18
19
# File 'lib/core/database.rb', line 17

def strategy strategy
  @strategy = strategy
end

#table(name, &block) ⇒ Object Also known as: collection



38
39
40
41
# File 'lib/core/database.rb', line 38

def table (name, &block)
  table = @strategy.new(@source_database, @destination_database, name, @user_defaults).process_fields(&block)
  @tables << table
end