Class: PostgresUpsert::ReadAdapters::IOAdapter
- Inherits:
-
Object
- Object
- PostgresUpsert::ReadAdapters::IOAdapter
- Defined in:
- lib/postgres_upsert/read_adapters/io_adapter.rb
Instance Method Summary collapse
- #columns ⇒ Object
- #continuous_write_enabled ⇒ Object
- #gets ⇒ Object
-
#initialize(source, options) ⇒ IOAdapter
constructor
A new instance of IOAdapter.
- #sanitize_options(options) ⇒ Object
Constructor Details
#initialize(source, options) ⇒ IOAdapter
Returns a new instance of IOAdapter.
4 5 6 7 |
# File 'lib/postgres_upsert/read_adapters/io_adapter.rb', line 4 def initialize(source, ) = () @source = source end |
Instance Method Details
#columns ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/postgres_upsert/read_adapters/io_adapter.rb', line 26 def columns @columns ||= begin columns_list = [:columns] ? [:columns].map(&:to_s) : [] if [: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([:delimiter]) end end columns_list = columns_list.map { |c| [:map][c.to_s] } if [:map] columns_list end end |
#continuous_write_enabled ⇒ Object
18 19 20 |
# File 'lib/postgres_upsert/read_adapters/io_adapter.rb', line 18 def continuous_write_enabled true end |
#gets ⇒ Object
22 23 24 |
# File 'lib/postgres_upsert/read_adapters/io_adapter.rb', line 22 def gets @source.gets end |
#sanitize_options(options) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/postgres_upsert/read_adapters/io_adapter.rb', line 9 def () .slice( :delimiter, :header, :columns, :map, :unique_key ).reverse_merge( header: true, delimiter: ',', ) end |