Sha256: 046e2103030cbd467fa6d1088eea66d5025c0709cf9c442baf8dfe19da5b0f14

Contents?: true

Size: 967 Bytes

Versions: 1

Compression:

Stored size: 967 Bytes

Contents

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

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

      # Only anonymize if rules are configured
      if RealDataTests.configuration.anonymization_rules.any?
        puts "\nAnonymizing records..."
        anonymizer = RealDataTests::DataAnonymizer.new(RealDataTests.configuration)
        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

    private

    def dump_file_path
      File.join(RealDataTests.configuration.dump_path, "#{@name}.sql")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
real_data_tests-0.1.0 lib/real_data_tests/test_data_builder.rb