Class: DataAnon::Strategy::Field::SelectFromDatabase

Inherits:
SelectFromFile show all
Includes:
Utils::Logging
Defined in:
lib/strategy/field/string/select_from_database.rb

Overview

Similar to SelectFromList with difference is the list of values are collected from the database table using distinct column query.

# values are collected using `select distinct state from customers` query
anonymize('State').using FieldStrategy::SelectFromDatabase.new('customers','state')

Instance Method Summary collapse

Methods included from Utils::Logging

#logger, #logger=

Methods inherited from SelectFromFile

#anonymize

Constructor Details

#initialize(table_name, field_name, connection_spec) ⇒ SelectFromDatabase

Returns a new instance of SelectFromDatabase.


14
15
16
17
18
19
20
# File 'lib/strategy/field/string/select_from_database.rb', line 14

def initialize table_name, field_name, connection_spec
  DataAnon::Utils::SourceDatabase.establish_connection connection_spec
  source = Utils::SourceTable.create table_name, []
  @values = source.select(field_name).uniq.collect { |record| record[field_name]}
  logger.debug "For field strategy #{table_name}:#{field_name} using values #{@values} "

end