Class: URI::MySQL
Constant Summary
collapse
- SCHEME =
'mysql'.freeze
- DEFAULT_HOST =
'localhost'.freeze
- DEFAULT_PORT =
3306
- DEFAULT_QUERY =
''.freeze
- COMPONENT =
[
:scheme,
:userinfo,
:host,
:path,
:query
].freeze
- @@mysqldump =
'mysqldump'.to_cmd.freeze
Instance Method Summary
collapse
Methods inherited from Generic
#add_query, #checkout, #commit, #mk_custom_opts, #pathname, #pathname=, #to_uri, #to_yaml_string, yaml_load
Instance Method Details
#mk_connection_opts ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/uri/mysql.rb', line 26
def mk_connection_opts
opts = []
opts << '-h' << @host
opts << '-P' << @port if @port != DEFAULT_PORT
opts << '-p' << @password if @password
opts << '-u' << @user if @user
opts
end
|
#mk_dump_opts(out = nil) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/uri/mysql.rb', line 36
def mk_dump_opts ( out=nil )
opts = %w[ -C ]
opts << '-r' << out if out
base, table = pathname.split
base, table = base.to_s, table.to_s
if base =~ /[\.\/]/
opts << table
else
if base =~ /\//
raise ArgumentError, "Use database/table not #{pathname}"
end
opts << base << table
end
opts
end
|
53
54
55
56
57
|
# File 'lib/uri/mysql.rb', line 53
def save
out = TempPath.new('dump', pathname.basename.to_s)
cmd = mysqldump + mk_connection_opts + mk_dump_opts(out) + mk_custom_opts
[out, cmd.run(runner)]
end
|