Sha256: 9bfba74139e27038e5cdec1e33997b8e3c82b8cca307dc426eca96bd5441c513
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
module PostgresUpsert module ReadAdapters class FileAdapter def initialize(source, options) @options = sanitize_options(options) @source = File.open(source, 'r') 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/file_adapter.rb |