Class: Storey::BuildsDumpCommand

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BuildsDumpCommand

Returns a new instance of BuildsDumpCommand.



6
7
8
9
10
11
# File 'lib/storey/builds_dump_command.rb', line 6

def initialize(options={})
  @options = options
  if @options[:database].blank?
    raise ArgumentError, 'database must be supplied'
  end
end

Instance Method Details

#executeObject



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
39
# File 'lib/storey/builds_dump_command.rb', line 13

def execute

  switches = {}
  switches['schema-only'] = nil if @options[:structure_only]
  switches['no-privileges'] = nil
  switches['no-owner'] = nil
  switches['host'] = @options[:host] if @options[:host].present?
  switches['username'] = @options[:username] if @options[:username].present?
  switches[:file] = Shellwords.escape(@options[:file])

  if @options[:schemas]
    schemas = @options[:schemas].split(',')
    schemas_switches = schemas.map do |part|
      Utils.command_line_switches_from({schema: Shellwords.escape(part) })
    end
  end

  command_parts = []
  if @options[:password].present?
    command_parts << "PGPASSWORD=#{@options[:password]}"
  end
  command_parts += ['pg_dump',
                   Utils.command_line_switches_from(switches),
                   schemas_switches,
                   @options[:database]]
  command_parts.compact.join(' ')
end