Module: PostgresUpsert
- Defined in:
- lib/postgres_upsert.rb,
lib/postgres_upsert/result.rb,
lib/postgres_upsert/writer.rb,
lib/postgres_upsert/table_writer.rb,
lib/postgres_upsert/model_to_model_adapter.rb,
lib/postgres_upsert/read_adapters/io_adapter.rb,
lib/postgres_upsert/read_adapters/file_adapter.rb,
lib/postgres_upsert/write_adapters/table_adapter.rb,
lib/postgres_upsert/read_adapters/active_record_adapter.rb,
lib/postgres_upsert/write_adapters/active_record_adapter.rb
Defined Under Namespace
Modules: ReadAdapters, WriteAdapters
Classes: ModelToModelAdapter, Result, TableWriter, Writer
Class Method Summary
collapse
Class Method Details
.read_adapter(source) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/postgres_upsert.rb', line 22
def read_adapter(source)
if [StringIO, File].include?(source.class)
ReadAdapters::IOAdapter
elsif [String].include?(source.class)
ReadAdapters::FileAdapter
elsif source < ActiveRecord::Base
ReadAdapters::ActiveRecordAdapter
else
raise "Source must be a Filename string, StringIO of data, or a ActiveRecord Class."
end
end
|
.write(destination, source, options = {}) ⇒ Object
16
17
18
19
20
|
# File 'lib/postgres_upsert.rb', line 16
def write(destination, source, options = {})
read_adapter = read_adapter(source).new(source, options)
write_adapter = write_adapter(destination).new(destination, options)
Writer.new(destination, write_adapter, read_adapter, options).write
end
|
.write_adapter(destination) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/postgres_upsert.rb', line 34
def write_adapter(destination)
if [String].include?(destination.class)
WriteAdapters::TableAdapter
elsif destination <= ActiveRecord::Base
WriteAdapters::ActiveRecordAdapter
else
raise "Destination must be an ActiveRecord class or a table name string"
end
end
|