class Koine::DbBkp::Mysql::Dump
Public Class Methods
new(config = {})
click to toggle source
# File lib/koine/db_bkp/mysql/dump.rb, line 7 def initialize(config = {}) config = normalize_config(config) @hostname = config.fetch(:hostname) @database = config.fetch(:database) @username = config[:username] @password = config[:password] @cli = Cli.new end
Public Instance Methods
to_sql_file(file)
click to toggle source
# File lib/koine/db_bkp/mysql/dump.rb, line 17 def to_sql_file(file) parts = ['mysqldump'] parts.push("-h #{escape(@hostname)}") if @hostname parts.push("-u #{escape(@username)}") if @username parts.push("-p#{escape(@password)}") if @password parts.push(@database) file = FileName.new(file) parts.push("> #{file}") @cli.execute(parts.join(' ')) end
Private Instance Methods
escape(string)
click to toggle source
# File lib/koine/db_bkp/mysql/dump.rb, line 34 def escape(string) Shellwords.escape(string) end
merge_url(config)
click to toggle source
# File lib/koine/db_bkp/mysql/dump.rb, line 43 def merge_url(config) url = config.delete(:url) return config unless url url = Addressable::URI.parse(url) config.merge( adapter: url.scheme, hostname: url.host, database: url.path.split('/').join(''), username: url.user, password: url.password ) end
normalize_config(config)
click to toggle source
# File lib/koine/db_bkp/mysql/dump.rb, line 38 def normalize_config(config) config = config.reject { |_k, v| ['', nil].include?(v) } merge_url(symbolize_keys(config)) end
symbolize_keys(hash)
click to toggle source
# File lib/koine/db_bkp/mysql/dump.rb, line 59 def symbolize_keys(hash) {}.tap do |new_hash| hash.each { |key, value| new_hash[key.to_sym] = value } end end