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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6db72f5a5672da5ee918069f82585950e325cb47
4
- data.tar.gz: a5db440198b9b79f3c2fb497abf2dc89c0ebbb6d
3
+ metadata.gz: 1dc22640b21bf3b9cf9c765dbab33d8c6da11fd1
4
+ data.tar.gz: 94e4ec0f279005ca04db5b69164db542dc1dcdd9
5
5
  SHA512:
6
- metadata.gz: f7d95ea5b111c74d41bf02551dd76d7b522a9dc611093452ef6dd64621cb8960a7902578c29738396d35f996a26cdd1a7bdd8cb6929615106e738cb62f25a462
7
- data.tar.gz: fea69a70e010fc80136200dd814903892b367a415a6c5298afebe8b2d0eafb4370462782df042b4b59fba4c4dbb9c9fd40bf89d7d12128463bce32fb5baf914a
6
+ metadata.gz: eff179fed36fd5d1b24818099057ea604cdda72a6c67576c3e261f7e56a5861ab97d55a052ae7cb790fcc017f020b1d948761bf12ad424974adcc1a97756ce75
7
+ data.tar.gz: 44f5534efac69c3d292170bcb12032ea6b18176945ee04d0e190cd50185e314109c8da4d51ff9ad88e743bc306600a0a058adb5f148474a2cb033707bdd08209
@@ -2,17 +2,17 @@ require 'logger'
2
2
 
3
3
  class MysqlImport
4
4
  class Logger < SimpleDelegator
5
- def initialize(logger, debug)
6
- case logger
5
+ def initialize(out, debug)
6
+ case out
7
7
  when String
8
- obj = ::Logger.new(arg)
8
+ obj = ::Logger.new(out)
9
9
  when NilClass
10
- obj = ::Logger.new(STDOUT)
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 = logger
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
- result.logger.info(' nothing...')
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
- @_parallel_opts ||= super.merge(
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
@@ -1,3 +1,3 @@
1
1
  class MysqlImport
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
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.0
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-29 00:00:00.000000000 Z
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