Sha256: 617d7fd61398cf199b276a33342a094355b5e7ea588ecd5b8ba7865816efc66a

Contents?: true

Size: 1 KB

Versions: 20

Compression:

Stored size: 1 KB

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 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

    private

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
real_data_tests-0.3.17 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.16 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.15 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.14 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.13 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.12 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.11 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.10 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.9 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.8 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.7 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.6 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.5 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.4 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.3 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.2 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.1 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.3.0 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.2.1 lib/real_data_tests/test_data_builder.rb
real_data_tests-0.2.0 lib/real_data_tests/test_data_builder.rb