class PgExport::ValueObjects::DumpFile

Constants

CHUNK_SIZE
MAPPING

Attributes

file[R]

Public Class Methods

new(file = Tempfile.new) click to toggle source
# File lib/pg_export/lib/pg_export/value_objects/dump_file.rb, line 8
def initialize(file = Tempfile.new)
  @file = file
end

Public Instance Methods

copy(cipher:) click to toggle source
# 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() { |read(CHUNK_SIZE) until eof?| ... } click to toggle source
# 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() click to toggle source
# File lib/pg_export/lib/pg_export/value_objects/dump_file.rb, line 12
def path
  file.path
end
read() click to toggle source
# File lib/pg_export/lib/pg_export/value_objects/dump_file.rb, line 24
def read
  file.read
end
rewind() click to toggle source
# File lib/pg_export/lib/pg_export/value_objects/dump_file.rb, line 20
def rewind
  file.rewind
end
size() click to toggle source
# File lib/pg_export/lib/pg_export/value_objects/dump_file.rb, line 16
def size
  file.size
end
size_human() click to toggle source
# 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) click to toggle source
# File lib/pg_export/lib/pg_export/value_objects/dump_file.rb, line 41
def write(&block)
  File.open(path, 'w', &block)
end