Class: YamlDb::Anonymizer::Dump

Inherits:
Dump
  • Object
show all
Defined in:
lib/yaml_db/anonymizer/dump.rb

Class Method Summary collapse

Class Method Details

.dump_table_columns(io, table) ⇒ Object



27
28
29
# File 'lib/yaml_db/anonymizer/dump.rb', line 27

def self.dump_table_columns(io, table)
  super(io, table) unless Anonymizer.definition.is_a?(Hash) && Anonymizer.definition[table.to_s] == :truncate
end

.dump_table_records(io, table) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yaml_db/anonymizer/dump.rb', line 5

def self.dump_table_records(io, table)
  return super(io, table) unless Anonymizer.definition.is_a? Hash
  return if Anonymizer.definition[table.to_s] == :truncate

  table_record_header(io)

  column_names = table_column_names(table)

  each_table_page(table) do |records|
    rows = SerializationHelper::Utils.unhash_records(records, column_names)
    records_anonymized = records.map do |record|
      # FIXME Why isn't there a map_with_index?
      record_anonymized = []
      record.each_with_index do |value, i|
        record_anonymized << Anonymizer.anonymize(table, column_names[i], value)
      end
      record_anonymized
    end
    io.write(YamlDb::Utils.chunk_records(records_anonymized))
  end
end

.tablesObject



31
32
33
# File 'lib/yaml_db/anonymizer/dump.rb', line 31

def self.tables
  ActiveRecord::Base.connection.tables
end