Class: BridgeCache::Plugins::CSVDump
- Inherits:
-
Object
- Object
- BridgeCache::Plugins::CSVDump
- Defined in:
- app/lib/bridge_cache/plugins/csv_dump.rb
Constant Summary collapse
- MAX_ROW_INTERVAL =
5000
Class Method Summary collapse
Class Method Details
.dump_row(clazz, row) ⇒ Object
28 29 30 31 |
# File 'app/lib/bridge_cache/plugins/csv_dump.rb', line 28 def self.dump_row(clazz, row) instance = initialze_row(clazz, row) dump_rows(clazz, [instance]) end |
.dump_to_table(clazz, file_path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/lib/bridge_cache/plugins/csv_dump.rb', line 8 def self.dump_to_table(clazz, file_path) count = 1 total = 0 rows = [] CSV.foreach(file_path, headers: true) do |row| total += 1 end CSV.foreach(file_path, headers: true) do |row| if count < MAX_ROW_INTERVAL rows << initialze_row(clazz, row) end if count % MAX_ROW_INTERVAL == 0 || count == total dump_rows(clazz, rows) count = 0 rows = [] end count += 1 end end |