Class: SampleDataDump::Gateways::LocalFileSystem
- Inherits:
-
Object
- Object
- SampleDataDump::Gateways::LocalFileSystem
- Extended by:
- Forwardable
- Defined in:
- lib/sample_data_dump/gateways/local_file_system.rb
Instance Method Summary collapse
- #clean_dump_directory ⇒ Object
- #compress_dump_file(table_configuration) ⇒ Object
- #decompress_compressed_dump_file(table_configuration) ⇒ Object
-
#initialize(settings) ⇒ LocalFileSystem
constructor
A new instance of LocalFileSystem.
- #load_table_configurations ⇒ Object
Constructor Details
#initialize(settings) ⇒ LocalFileSystem
Returns a new instance of LocalFileSystem.
15 16 17 18 19 20 |
# File 'lib/sample_data_dump/gateways/local_file_system.rb', line 15 def initialize(settings) @settings = settings @sample_data_dump_config = YAML.load_file(config_file_path) `mkdir -p #{compacted_dump_directory}` end |
Instance Method Details
#clean_dump_directory ⇒ Object
22 23 24 25 26 |
# File 'lib/sample_data_dump/gateways/local_file_system.rb', line 22 def clean_dump_directory `rm -rf #{compacted_dump_directory}/*.sql` `rm -rf #{compacted_dump_directory}/*.sql.tar.gz` Dry::Monads::Success(true) end |
#compress_dump_file(table_configuration) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sample_data_dump/gateways/local_file_system.rb', line 28 def compress_dump_file(table_configuration) dump_file_helper = Helpers::DumpFile.new(table_configuration, @settings) uncompressed_file_path = dump_file_helper.local_dump_file_path uncompressed_file_name = dump_file_helper.local_dump_file_name compressed_file_name = dump_file_helper.local_compressed_dump_file_name compressed_file_path = dump_file_helper.local_compressed_dump_file_path unless File.exists?(uncompressed_file_path) return Dry::Monads::Failure("No file found at #{uncompressed_file_path}") end `cd #{compacted_dump_directory}; tar -zcf #{compressed_file_name} #{uncompressed_file_name}` if File.exist?(compressed_file_path) Dry::Monads::Success(compressed_file_path) else Dry::Monads::Failure("No file found at #{compressed_file_path} after compressing") end end |
#decompress_compressed_dump_file(table_configuration) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sample_data_dump/gateways/local_file_system.rb', line 48 def decompress_compressed_dump_file(table_configuration) dump_file_helper = Helpers::DumpFile.new(table_configuration, @settings) compressed_file_name = dump_file_helper.local_compressed_dump_file_name compressed_file_path = dump_file_helper.local_compressed_dump_file_path unless File.exist?(compressed_file_path) return Dry::Monads::Failure("#{compressed_file_path} does not exist for decompressing!") end `cd #{compacted_dump_directory}; tar -zxf #{compressed_file_name}` Dry::Monads::Success(true) end |
#load_table_configurations ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sample_data_dump/gateways/local_file_system.rb', line 60 def load_table_configurations result = [] @sample_data_dump_config.each_pair do |schema_name, schema_config_hash| schema_config_hash.each_pair do |table_name, table_config_hash| dump_where = table_config_hash&.[]('dump_where') || '1 = 1' obfuscate_columns = table_config_hash&.[]('obfuscate_columns') || [] result << Entities::TableConfiguration.new( schema_name: schema_name, table_name: table_name, dump_where: dump_where, obfuscate_columns: obfuscate_columns ) end end Dry::Monads::Success(result) end |