Sha256: 680e962682796104282c2102ee2bcc259391919185d7798ba270e1f32cafb8a1
Contents?: true
Size: 876 Bytes
Versions: 3
Compression:
Stored size: 876 Bytes
Contents
class PgExport module Dump class Base extend Forwardable include SizeHuman CHUNK_SIZE = (2**16).freeze def_delegators :file, :path, :read, :write, :<<, :rewind, :close, :size, :eof? def initialize @file = Tempfile.new('dump') end def ext '' end def open(operation_type, &block) case operation_type.to_sym when :read then File.open(path, 'r', &block) when :write then File.open(path, 'w', &block) else raise ArgumentError, 'Operation type can be only :read or :write' end end def each_chunk open(:read) do |file| yield file.read(CHUNK_SIZE) until file.eof? end end def to_s "#{name || self.class} #{file.class} (#{size_human})" end private attr_reader :file end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pg_export-0.5.0 | lib/pg_export/entities/dump/base.rb |
pg_export-0.4.1 | lib/pg_export/entities/dump/base.rb |
pg_export-0.4.0 | lib/pg_export/entities/dump/base.rb |