mysql_import 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mysql_import/logger.rb +22 -19
- data/lib/mysql_import/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dc22640b21bf3b9cf9c765dbab33d8c6da11fd1
|
4
|
+
data.tar.gz: 94e4ec0f279005ca04db5b69164db542dc1dcdd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eff179fed36fd5d1b24818099057ea604cdda72a6c67576c3e261f7e56a5861ab97d55a052ae7cb790fcc017f020b1d948761bf12ad424974adcc1a97756ce75
|
7
|
+
data.tar.gz: 44f5534efac69c3d292170bcb12032ea6b18176945ee04d0e190cd50185e314109c8da4d51ff9ad88e743bc306600a0a058adb5f148474a2cb033707bdd08209
|
data/lib/mysql_import/logger.rb
CHANGED
@@ -2,17 +2,17 @@ require 'logger'
|
|
2
2
|
|
3
3
|
class MysqlImport
|
4
4
|
class Logger < SimpleDelegator
|
5
|
-
def initialize(
|
6
|
-
case
|
5
|
+
def initialize(out, debug)
|
6
|
+
case out
|
7
7
|
when String
|
8
|
-
obj = ::Logger.new(
|
8
|
+
obj = ::Logger.new(out)
|
9
9
|
when NilClass
|
10
|
-
obj = ::Logger.new(
|
10
|
+
obj = ::Logger.new(nil)
|
11
|
+
when STDOUT, STDERR
|
12
|
+
obj = ::Logger.new(out)
|
11
13
|
obj.formatter = ->(seveity, datetime, progname, message) { "#{String === message ? message : message.inspect}\n" }
|
12
|
-
when FalseClass
|
13
|
-
obj = ::Logger.new('/dev/null')
|
14
14
|
else
|
15
|
-
obj =
|
15
|
+
obj = out
|
16
16
|
end
|
17
17
|
|
18
18
|
obj.level = debug ? ::Logger::DEBUG : ::Logger::INFO
|
@@ -23,16 +23,7 @@ class MysqlImport
|
|
23
23
|
module Logging
|
24
24
|
def initialize(config, opts ={}, sql_opts = {})
|
25
25
|
@logger = Logger.new(opts[:log], opts.fetch(:debug, false))
|
26
|
-
|
27
|
-
LoadDataInfile2::Client.class_exec(@logger) do |logger|
|
28
|
-
define_method :build_sql_with_logging do |file, options|
|
29
|
-
options = {} unless options
|
30
|
-
build_sql_without_logging(file, options).tap {|sql| logger.debug("sql: #{sql}") }
|
31
|
-
end
|
32
|
-
alias_method :build_sql_without_logging, :build_sql
|
33
|
-
alias_method :build_sql, :build_sql_with_logging
|
34
|
-
end
|
35
|
-
|
26
|
+
embed_logger
|
36
27
|
super
|
37
28
|
end
|
38
29
|
|
@@ -43,7 +34,7 @@ class MysqlImport
|
|
43
34
|
if result.imported.size > 0
|
44
35
|
result.imported.sort.each {|t| logger.info(" #{t[0]} (#{t[1]} sec)") }
|
45
36
|
else
|
46
|
-
|
37
|
+
logger.info(' nothing...')
|
47
38
|
end
|
48
39
|
if result.skipped.size > 0
|
49
40
|
logger.info('Skipped tables:')
|
@@ -58,13 +49,25 @@ class MysqlImport
|
|
58
49
|
attr_reader :logger
|
59
50
|
|
60
51
|
def parallel_opts
|
61
|
-
@
|
52
|
+
@parallel_opts ||= super.merge(
|
62
53
|
finish: proc do |item, index, _result|
|
63
54
|
logger.debug("parallel_item: #{item.inspect}")
|
64
55
|
logger.debug("parallel_index: #{index}")
|
65
56
|
end
|
66
57
|
)
|
67
58
|
end
|
59
|
+
|
60
|
+
def embed_logger
|
61
|
+
unless LoadDataInfile2::Client.instance_methods.include?(:build_sql_with_logging)
|
62
|
+
LoadDataInfile2::Client.class_exec(logger) do |logger|
|
63
|
+
define_method :build_sql_with_logging do |file, options = {}|
|
64
|
+
build_sql_without_logging(file, options).tap {|sql| logger.debug("sql: #{sql}") }
|
65
|
+
end
|
66
|
+
alias_method :build_sql_without_logging, :build_sql
|
67
|
+
alias_method :build_sql, :build_sql_with_logging
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
68
71
|
end
|
69
72
|
|
70
73
|
prepend Logging
|
data/lib/mysql_import/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql_import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nalabjp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: load_data_infile2
|