class DataAnon::Core::Database

Public Class Methods

new(name) click to toggle source
# 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

Public Instance Methods

anonymize() click to toggle source
# 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
collection(name, &block)
Alias for: table
default_field_strategies(default_strategies) click to toggle source
# File lib/core/database.rb, line 34
def default_field_strategies default_strategies
  @user_defaults = default_strategies
end
destination_db(connection_spec) click to toggle source
# File lib/core/database.rb, line 30
def destination_db connection_spec
  @destination_database = connection_spec
end
execution_strategy(execution_strategy) click to toggle source
# 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) click to toggle source
# File lib/core/database.rb, line 26
def source_db connection_spec
  @source_database = connection_spec
end
strategy(strategy) click to toggle source
# File lib/core/database.rb, line 17
def strategy strategy
  @strategy = strategy
end
table(name, &block) click to toggle source
# 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
Also aliased as: collection