Sha256: b5d1461bb9066b69516cffd3ca85da0106346bebc2756cf1699a9fb6527f85ec
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module PostgresUpsert module ReadAdapters class IOAdapter def initialize(source, options) @options = sanitize_options(options) @source = source end def sanitize_options(options) options.slice( :delimiter, :header, :columns, :map, :unique_key ).reverse_merge( header: true, delimiter: ',', ) end def continuous_write_enabled true end def gets @source.gets end def columns @columns ||= begin columns_list = @options[:columns] ? @options[:columns].map(&:to_s) : [] if @options[:header] # if header is present, we need to strip it from io, whether we use it for the columns list or not. line = gets if columns_list.empty? columns_list = line.strip.split(@options[:delimiter]) end end columns_list = columns_list.map { |c| @options[:map][c.to_s] } if @options[:map] columns_list end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
postgres_upsert-5.1.0 | lib/postgres_upsert/read_adapters/io_adapter.rb |