Module: Capistrano::DSL::Mysqldump

Defined in:
lib/capistrano/dsl/mysqldump.rb

Instance Method Summary collapse

Instance Method Details

#mysqldump_credential_options(username, password) ⇒ Object

returns credential options for a given username and password when given an empty or nil password, does not include p: in the returned hash



28
29
30
31
32
33
# File 'lib/capistrano/dsl/mysqldump.rb', line 28

def mysqldump_credential_options(username, password)
  {}.tap do |opts|
    opts[:u] = username
    opts[:p] = password if password == true || password && !password.empty?
  end
end

#mysqldump_options_string(options = nil) ⇒ Object

converts a hash of options into a string. drops falsey-valued keys.

‘’foo’, ‘single-transaction’ => true, ignore-tables’ => ‘bar’, p: nil‘

> ‘-ufoo –ignore-tables=bar –single-transaction



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/capistrano/dsl/mysqldump.rb', line 11

def mysqldump_options_string(options = nil)
  options
  options.map do |k,v|
    next unless v
    used_value = v == true ? nil : v
    used_prefix, used_join = if k.length == 1
                               ["-", '']
                             else
                               ["--", '=']
                             end

    "#{used_prefix}#{[k, used_value].compact.join used_join}"
  end.compact.join ' '
end