Class: Storey::GenLoadCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/storey/gen_load_command.rb

Class Method Summary collapse

Class Method Details

.call(file: nil, command: nil, database_url: Storey.configuration.database_url, database: nil, username: nil, host: nil, port: nil, password: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/storey/gen_load_command.rb', line 4

def self.call(
  file: nil,
  command: nil,
  database_url: Storey.configuration.database_url,
  database: nil,
  username: nil,
  host: nil,
  port: nil,
  password: nil
)
  switches = {}
  if file.present?
    switches[:file] = Shellwords.escape(file)
  end
  switches[:command] = %Q("#{command}") if command.present?

  command_parts = ["psql"]

  if database_url.present?
    command_parts << database_url
  else
    switches[:dbname] = database
    switches[:username] = username if username.present?
    switches[:host] = host if host.present?
    switches[:port] = port if port.present?
    if password.present?
      switches[:password] = password
    else
      switches['no-password'] = nil
    end
  end

  command_parts << Utils.command_line_switches_from(switches)
  command_parts.join(' ')
end