Class: DbBackupTool::Dumper

Inherits:
Object
  • Object
show all
Defined in:
lib/db_backup_tool/dumper.rb

Instance Method Summary collapse

Constructor Details

#initialize(table, options = {}) ⇒ Dumper

Returns a new instance of Dumper.



4
5
6
# File 'lib/db_backup_tool/dumper.rb', line 4

def initialize(table, options = {})
  @table, @options = table, options.dup
end

Instance Method Details

#batch_sizeObject



16
17
18
# File 'lib/db_backup_tool/dumper.rb', line 16

def batch_size
  @options[:batch_size] || 1000
end

#dump(io) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/db_backup_tool/dumper.rb', line 8

def dump(io)
  csv = CSV.new(io, headers: true, write_headers: true)
  csv << @table.column_names
  @table.each_record(batch_size) do |record|
    csv << record.values_at(*(@table.column_names))
  end
end