Class: RealDataTests::TestDataBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/real_data_tests/test_data_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(record, name: nil) ⇒ TestDataBuilder

Returns a new instance of TestDataBuilder.



3
4
5
6
# File 'lib/real_data_tests/test_data_builder.rb', line 3

def initialize(record, name: nil)
  @record = record
  @name = name || "#{record.class.name.underscore}_#{record.id}"
end

Instance Method Details

#create_dump_fileObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/real_data_tests/test_data_builder.rb', line 8

def create_dump_file
  records = RealDataTests::RecordCollector.new(@record).collect

  # Only anonymize if rules are configured in the current preset
  if RealDataTests.configuration.current_preset.anonymization_rules.any?
    puts "\nAnonymizing records..."
    anonymizer = RealDataTests::DataAnonymizer.new(RealDataTests.configuration.current_preset)
    records = anonymizer.anonymize_records(records)
  end

  dump_content = RealDataTests::PgDumpGenerator.new(records).generate
  dump_path = dump_file_path
  FileUtils.mkdir_p(File.dirname(dump_path))
  File.write(dump_path, dump_content)
  puts "\nDump file created at: #{dump_path}"
  dump_path
end