Commit e9c28fd0 authored by Jacob Schatz's avatar Jacob Schatz Committed by Micaël Bergeron

Updated config to take destination for files.

parent 1ac6a03f
output:
csv: '/tmp/'
tables: tables:
approvals: approvals:
whitelist: whitelist:
......
...@@ -24,16 +24,19 @@ module Pseudonymity ...@@ -24,16 +24,19 @@ module Pseudonymity
end end
class Table class Table
config = {}
def initialize def initialize
@config = {}
@csv_output = ""
parse_config parse_config
end end
def tables_to_csv def tables_to_csv
tables = @config["tables"] tables = @config["tables"]
@csv_output = @config["output"]["csv"]
if not File.directory?(@csv_output)
puts "No such directory #{@csv_output}"
return
end
tables.map do | k, v | tables.map do | k, v |
table_to_csv(k, v["whitelist"], v["pseudo"]) table_to_csv(k, v["whitelist"], v["pseudo"])
end end
...@@ -43,7 +46,7 @@ module Pseudonymity ...@@ -43,7 +46,7 @@ module Pseudonymity
sql = "SELECT #{whitelist_columns.join(",")} from #{table}" sql = "SELECT #{whitelist_columns.join(",")} from #{table}"
results = ActiveRecord::Base.connection.exec_query(sql) results = ActiveRecord::Base.connection.exec_query(sql)
return if results.empty? return if results.empty?
anon = Anon.new(pseudonymity_columns) anon = Anon.new(pseudonymity_columns)
write_to_csv_file(table, anon.anonymize(results)) write_to_csv_file(table, anon.anonymize(results))
end end
...@@ -53,7 +56,7 @@ module Pseudonymity ...@@ -53,7 +56,7 @@ module Pseudonymity
end end
def write_to_csv_file(title, contents) def write_to_csv_file(title, contents)
file_path = "/tmp/#{title}.csv" file_path = "#{@csv_output}/#{title}_#{Time.now.to_i}.csv"
column_names = contents.first.keys column_names = contents.first.keys
contents = CSV.generate do | csv | contents = CSV.generate do | csv |
csv << column_names csv << column_names
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment