tee_logger 3.0.0 → 3.0.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: fac48b2aa959b362ac7fa364c0a343a2f1588616
4
- data.tar.gz: d14d1e2b0458879b5ddcbd11ae59a9514d29c2e5
3
+ metadata.gz: 7a6bbfeaad4ce3cc439f815a4d72468ea056dd47
4
+ data.tar.gz: 9a559bcaa02d344745ba5ec2d0f3f2fc397dde92
5
5
  SHA512:
6
- metadata.gz: 61e4ff27817c8717f338f38a01500c08041a32dbb0243d40c1dc2211be28b4f8638f38b692c9cd3d9ee0747129b1b8b2d59950b1522afebf24b887e0c042fe40
7
- data.tar.gz: fda1d7ffb55beeecc1bca0241005a40d59adabdc92e1116dcc3939465e1f8959d89ab8ea695dfcde102c53183bcda096ba97d0806ddf3ab0f63df1614fcdce16
6
+ metadata.gz: d8e217bda8ad154e33bb6e819e1b563c1b0d15026be829651b2b8c66bd13d3d50ada1581c50e8bf4629df76b606df4ebe59347bd161ca23090ee6082403cca17
7
+ data.tar.gz: 64a1db311741ce7907741c68fa7016fc8391c864fdfb295f5c70b7f73a586ff29d4707e012040323e6e0a9bfd2e2263196c3ed486f4d48901c598ee5a7cbf3a3
@@ -1,3 +1,6 @@
1
+ # v3.0.1
2
+ - refactoring for [issue #9](https://github.com/k-ta-yamada/tee_logger/issues/9)
3
+
1
4
  # v3.0.0
2
5
  - [issue #4](https://github.com/k-ta-yamada/tee_logger/issues/4)
3
6
  logging method's parametrer disabling_target change to enabling_targe
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Test Coverage](https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/coverage.svg)](https://codeclimate.com/github/k-ta-yamada/tee_logger/coverage)
5
5
 
6
6
  > Sorry. In from version 2 to version 3, changed usage.
7
- > see also [CHANGELOG.md](/CHANGELOG.md#v300).
7
+ > see also [CHANGELOG.md](https://github.com/k-ta-yamada/tee_logger/blob/master/CHANGELOG.md).
8
8
 
9
9
  - [Rubygems.org](https://rubygems.org/gems/tee_logger)
10
10
  - [GitHub](https://github.com/k-ta-yamada/tee_logger)
@@ -20,25 +20,21 @@ module TeeLogger
20
20
  class TeeLogger
21
21
  class << self
22
22
  # @!macro [attach] logging_methods
23
- # @!method $1(progname = nil, disabling_target = nil, &block)
23
+ # @!method $1(progname = nil, *options, &block)
24
24
  # logging $1 level message.
25
25
  # @param progname see also Logger
26
- # @param disabling_target (Symbol) valid values => [:console, :logfile]
26
+ # @param options [Array]
27
+ # @option options [Fixnum] indent_level
28
+ # @option options [Symbol] enabling_target
29
+ # valid values => [:console, :logfile]
27
30
  # @param &block see also Logger
28
31
  # @return true
29
32
  # @see Logger
30
33
  def define_logging_methods(name)
31
34
  define_method(name) do |progname = nil, *options, &block|
32
- opts = parse_to_hash_from(options)
33
-
34
- disabling_target = reverse_target(opts[:enabling_target])
35
- progname, block = indentation(progname, block, opts[:indent_level])
36
-
37
- if disabling_target.nil?
38
- logging(name, progname, &block)
39
- else
40
- disable(disabling_target) { logging(name, progname, &block) }
41
- end
35
+ logdev_name, indent_level = extract_options(options).values
36
+ progname, block = indentation(progname, block, indent_level)
37
+ logging(name, progname, logdev_name, &block)
42
38
  end
43
39
  end
44
40
  private :define_logging_methods
@@ -124,9 +120,13 @@ module TeeLogger
124
120
 
125
121
  private
126
122
 
127
- def logging(name, progname, &block)
128
- @console.send(name, progname, &block)
129
- @logfile.send(name, progname, &block)
123
+ def logging(name, progname, logdev_name = nil, &block)
124
+ if logdev_name
125
+ disable(logdev_name) { logging(name, progname, &block) }
126
+ else
127
+ @console.send(name, progname, &block)
128
+ @logfile.send(name, progname, &block)
129
+ end
130
130
  end
131
131
  end
132
132
  end
@@ -2,32 +2,29 @@
2
2
  module TeeLogger
3
3
  # util
4
4
  module Utils
5
+ # LOGDEV_NAMES not incuded error
5
6
  class IncorrectNameError < StandardError; end
6
-
7
+ #
8
+ class IncorrectOptionError < StandardError; end
9
+ # using private method #parse_to_hash
10
+ ParsedOption = Struct.new(:logdev_name, :indent_level)
7
11
  # defined log devices names
8
- LOGDEVS = %i(console logfile)
12
+ LOGDEV_NAMES = [:console, :logfile]
13
+ # defined reverse names
14
+ LOGDEV_REVERSE = { console: :logfile, logfile: :console }
9
15
 
10
16
  private
11
17
 
12
- def parse_to_hash_from(options)
13
- result = { enabling_target: nil, indent_level: 0 }
14
- options.each_with_object(result) do |val, obj|
15
- if val.is_a?(Symbol)
16
- correct_name?(val)
17
- obj[:enabling_target] = LOGDEVS.include?(val) ? val : nil
18
- elsif val.is_a?(Fixnum)
19
- obj[:indent_level] = val
18
+ def extract_options(options)
19
+ options.each_with_object(ParsedOption.new(nil, 0)) do |val, obj|
20
+ case val
21
+ when Symbol then obj.logdev_name = name_reverse(val)
22
+ when Fixnum then obj.indent_level = val
23
+ else incorrect_option_error(val)
20
24
  end
21
25
  end
22
26
  end
23
27
 
24
- def reverse_target(logdev_name)
25
- case logdev_name
26
- when :console then :logfile
27
- when :logfile then :console
28
- end
29
- end
30
-
31
28
  def indentation(progname, block, indent_level)
32
29
  if block.nil?
33
30
  progname = "#{' ' * indent_level}#{formatting(progname)}"
@@ -39,22 +36,30 @@ module TeeLogger
39
36
  end
40
37
 
41
38
  def formatting(val)
42
- if val.is_a?(Symbol)
43
- ":#{val}"
44
- elsif val.nil?
45
- 'nil'
46
- else
47
- val
39
+ case val
40
+ when Symbol then ":#{val}"
41
+ when nil then 'nil'
42
+ else val
48
43
  end
49
44
  end
50
45
 
51
- def correct_name?(logdev_name)
52
- if LOGDEVS.include?(logdev_name)
53
- true
54
- else
55
- fail IncorrectNameError,
56
- "logdev_name=[:#{logdev_name}]:logdev_name is :console or :logfile"
57
- end
46
+ def name_reverse(val)
47
+ correct_name?(val)
48
+ LOGDEV_REVERSE[val]
49
+ end
50
+
51
+ def correct_name?(name)
52
+ LOGDEV_NAMES.include?(name) ? true : incorrect_name_error(name)
53
+ end
54
+
55
+ def incorrect_name_error(name)
56
+ fail IncorrectNameError,
57
+ "logdev_name is :console or :logfile. logdev_name=[:#{name}]"
58
+ end
59
+
60
+ def incorrect_option_error(val)
61
+ fail IncorrectOptionError,
62
+ "option params is Symbol or Fixnum. class=[#{val.class}]"
58
63
  end
59
64
 
60
65
  def logdev_instance(logdev_name)
@@ -1,5 +1,5 @@
1
1
  # namespace
2
2
  module TeeLogger
3
3
  # version number
4
- VERSION = '3.0.0'
4
+ VERSION = '3.0.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tee_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - k-ta-yamada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-06 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler