Class: PgExport::ValueObjects::DumpFile
- Inherits:
-
Object
- Object
- PgExport::ValueObjects::DumpFile
- Defined in:
- lib/pg_export/lib/pg_export/value_objects/dump_file.rb
Instance Method Summary collapse
- #copy(cipher:) ⇒ Object
- #each_chunk ⇒ Object
-
#initialize(file = Tempfile.new) ⇒ DumpFile
constructor
A new instance of DumpFile.
- #path ⇒ Object
- #read ⇒ Object
- #rewind ⇒ Object
- #size ⇒ Object
- #size_human ⇒ Object
- #write(&block) ⇒ Object
Constructor Details
#initialize(file = Tempfile.new) ⇒ DumpFile
Returns a new instance of DumpFile.
8 9 10 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 8 def initialize(file = Tempfile.new) @file = file end |
Instance Method Details
#copy(cipher:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 28 def copy(cipher:) cipher.reset new_self = self.class.new new_self.write do |f| each_chunk do |chunk| f << cipher.update(chunk) end f << cipher.final end new_self end |
#each_chunk ⇒ Object
45 46 47 48 49 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 45 def each_chunk File.open(path, 'r') do |file| yield file.read(CHUNK_SIZE) until file.eof? end end |
#path ⇒ Object
12 13 14 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 12 def path file.path end |
#read ⇒ Object
24 25 26 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 24 def read file.read end |
#rewind ⇒ Object
20 21 22 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 20 def rewind file.rewind end |
#size ⇒ Object
16 17 18 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 16 def size file.size end |
#size_human ⇒ Object
51 52 53 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 51 def size_human MAPPING.each_pair { |e, s| return "#{(size.to_f / (s / 1024)).round(2)}#{e}" if size < s } end |
#write(&block) ⇒ Object
41 42 43 |
# File 'lib/pg_export/lib/pg_export/value_objects/dump_file.rb', line 41 def write(&block) File.open(path, 'w', &block) end |