module RDB::Dumper

Public Class Methods

new(source, destination, options = {}) click to toggle source
# File lib/rdb/dumper.rb, line 5
def initialize(source, destination, options = {})
  @source = source
  @destination = destination
  @options = options
  @output = nil
end

Public Instance Methods

<<(buffer) click to toggle source
# File lib/rdb/dumper.rb, line 12
def <<(buffer)
  @output << buffer unless @output.nil?; nil
end
dump() click to toggle source
# File lib/rdb/dumper.rb, line 28
def dump
  raise RuntimeException, 'Output stream already opened' if @output

  with_streams do |input, output|
    @output = output
    Reader.read(input, callbacks: self)
  end
end
with_streams(&block) click to toggle source
# File lib/rdb/dumper.rb, line 16
def with_streams(&block)
  input = open(@source, 'rb') unless @source.kind_of? IO
  output = open(@destination, 'wb') unless @destination.kind_of? IO

  begin
    block.call(input, output)
  ensure
    input.close
    output.close
  end
end