Class: DBA::Load

Inherits:
Command show all
Defined in:
lib/dba/load.rb

Constant Summary collapse

ADAPTERS =
{
  '.csv' => :CSV,
  '.jsonl' => :LDJSON,
  '.ldjson' => :LDJSON,
  '.ndjson' => :LDJSON,
  '.yml' => :YAML,
  '.yaml' => :YAML
}

Instance Attribute Summary

Attributes inherited from Command

#database, #table_name

Instance Method Summary collapse

Methods inherited from Command

arity_check, #initialize

Constructor Details

This class inherits a constructor from DBA::Command

Instance Method Details

#call(path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dba/load.rb', line 13

def call(path)
  file_list(path).each do |file|
    extension = File.extname(file)

    adapter = ADAPTERS.fetch(extension) { raise DBA::Error, 'unsupported file extension' }

    adapter = DBA.const_get(adapter)

    table_name = File.basename(file, extension).to_sym

    adapter.load(file, database, table_name)
  end
end