class FakePipe::Postgres::CopyBlock
Finds COPY… text blocks inside of `pg_dumps`
Constants
- COLUMN_SPLITTER
- DELIMITER
Public Instance Methods
on_start_text(match, line)
click to toggle source
@return [Hash<Integer,String>] Index for column ordinal and column name: { 1 => column_name }
# File lib/fake_pipe/postgres/copy_block.rb, line 16 def on_start_text(match, line) @table = match[:table] @columns = match[:columns].split(COLUMN_SPLITTER) @column_idx = Hash[@columns.map.with_index { |name, i| [i, name] }] end
parse(line)
click to toggle source
Postgres
COPY format is NOT CSV. > www.postgresql.org/docs/9.1/static/sql-copy.html
@return [String] maybe mutated by `delegate.on_cell`
# File lib/fake_pipe/postgres/copy_block.rb, line 26 def parse(line) row = line.split(DELIMITER) faked = row.map.with_index do |cell, i| if cell.blank? || cell == '\N' # Don't acknowledge null cells cell else delegate.on_cell(table: @table, column: @column_idx[i], cell: cell) end end faked.join(DELIMITER) end