Sha256: 8d6b56f834b239396225882d6814c8cffda45e95fc83c418f9677280e4f0e42a
Contents?: true
Size: 1.66 KB
Versions: 5
Compression:
Stored size: 1.66 KB
Contents
module Spontaneous module Utils module Database class MySQLDumper def initialize(database) @database = database end def name "mysql" end def load(path) system(load_command(path)) end def load_command(path) options = [ "mysql", option(:password), option(:user), option(:default_character_set), database_name ] if path =~ /\.gz$/ options = ["gunzip", "<", path, "|"].concat(options) end command = options.join(" ") end def dump(path, tables = nil) system(dump_command(path, tables)) end def dump_command(path, tables = nil) options = [ option(:password), option(:user), option(:default_character_set), database_name ] unless tables.nil? options.push(tables.join(" ")) end options.push( "| gzip") if path =~ /\.gz$/ command = %(mysqldump #{options.join(" ")} > #{path} ) end def database_name @database.opts[:database] end def user @database.opts[:user] end def password @database.opts[:password] end def default_character_set "UTF8" end def option(option, add_if_nil=false) value = self.send(option) if !value.nil? or add_if_nil "--#{option.to_s.gsub(/_/, '-')}=#{value}" else "" end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems