module Capistrano::DSL::Mysqldump

Public Instance Methods

mysqldump_credential_options(username, password) click to toggle source

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

# 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) click to toggle source

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

`{u: 'foo', 'single-transaction' => true, ignore-tables' => 'bar', p: nil}`

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

# 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