class DBA::Load

Constants

ADAPTERS

Public Instance Methods

call(path) click to toggle source
# File lib/dba/load.rb, line 11
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

Private Instance Methods

file_list(path) click to toggle source
# File lib/dba/load.rb, line 27
def file_list(path)
  if File.directory?(path)
    Dir.glob(File.join(path, '*.{csv,ldjson,yml,yaml}'))
  else
    [path]
  end
end