Class: DbBackupTool::Loader
- Inherits:
-
Object
- Object
- DbBackupTool::Loader
- Defined in:
- lib/db_backup_tool/loader.rb
Instance Method Summary collapse
- #batch_size ⇒ Object
-
#initialize(table, options = {}) ⇒ Loader
constructor
A new instance of Loader.
- #load(io) ⇒ Object
Constructor Details
#initialize(table, options = {}) ⇒ Loader
Returns a new instance of Loader.
4 5 6 |
# File 'lib/db_backup_tool/loader.rb', line 4 def initialize(table, = {}) @table, @options = table, .dup end |
Instance Method Details
#batch_size ⇒ Object
17 18 19 |
# File 'lib/db_backup_tool/loader.rb', line 17 def batch_size @options[:batch_size] || 1000 end |
#load(io) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/db_backup_tool/loader.rb', line 8 def load(io) csv = CSV.new(io, headers: true) @table.truncate csv.each_slice(batch_size) do |rows| @table.update rows.map(&:to_hash) end end |