yell 2.0.0 → 2.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: 2158e0eeef9ba26f9dfeb6dca85a6f95a2d90c95
4
- data.tar.gz: 9dff5c3e776e545c9704d2fcf574716b87b32c34
3
+ metadata.gz: aa1069934b048c65d5dbabcf49945cd08defdf1c
4
+ data.tar.gz: ed6c2a345a27ebc070468601ba71542ed90c0fa8
5
5
  SHA512:
6
- metadata.gz: b0f4c57e784a8b45379a2853392de8fb8699ca5155ad5d5333da37d0fdd684c149bac7a86a69dc2e877963b1d55d1119fa7d68b95a161d05c7a01fbab513e5be
7
- data.tar.gz: 9885f26f334b19200cfb68288cc8720a192144b3a42cd20b33355bdb2300ec8c9debed4a37bcc0ee7f529f6082b4d3c54ac320d929cfff9577249f0aa00b41e5
6
+ metadata.gz: 6622eba193295d3150f98c3dc17cc378b0ef373870cb8c01b8644baa32a4871bba79a24e058e02961dde0bca37005970da490ed2f36f43d6f56b754a49b727f7
7
+ data.tar.gz: 76098942230da8a9997d0010259802ca4dfaa02ea9b6a15ba642026987136a05dfc5019704ccb27263a48e4c54ff6265a14929e470ae1f7d03add1308b853ee3
@@ -90,20 +90,29 @@ module Yell #:nodoc:
90
90
  end
91
91
 
92
92
  # @private
93
- def _deprecate( version, message, options = {} )
93
+ def __deprecate__( version, message, options = {} ) #:nodoc:
94
94
  messages = ["Deprecation Warning (since v#{version}): #{message}" ]
95
95
  messages << " before: #{options[:before]}" if options[:before]
96
96
  messages << " after: #{options[:after]}" if options[:after]
97
97
 
98
- _warn(*messages)
98
+ __warn__(*messages)
99
99
  end
100
100
 
101
101
  # @private
102
- def _warn( *messages )
102
+ def __warn__( *messages ) #:nodoc:
103
103
  $stderr.puts "[Yell] " + messages.join("\n")
104
104
  rescue Exception => e
105
105
  # do nothing
106
106
  end
107
+
108
+ # @private
109
+ def __fetch__( hash, *args )
110
+ options = args.last.is_a?(Hash) ? args.pop : {}
111
+ value = args.map { |key| hash.fetch(key.to_sym, hash[key.to_s]) }.compact.first
112
+
113
+ value.nil? ? options[:default] : value
114
+ end
115
+
107
116
  end
108
117
 
109
118
  end
@@ -54,7 +54,7 @@ module Yell #:nodoc:
54
54
  # @example
55
55
  # Yell::Adapters.register( :myadapter, MyAdapter )
56
56
  def self.register( name, klass )
57
- @adapters[name] = klass
57
+ @adapters[name.to_sym] = klass
58
58
  end
59
59
 
60
60
  # Returns an instance of the given processor type.
@@ -67,7 +67,7 @@ module Yell #:nodoc:
67
67
  adapter = case name
68
68
  when STDOUT then @adapters[:stdout]
69
69
  when STDERR then @adapters[:stderr]
70
- else @adapters[name]
70
+ else @adapters[name.to_sym]
71
71
  end
72
72
 
73
73
  raise AdapterNotFound.new(name) if adapter.nil?
@@ -52,7 +52,7 @@ module Yell #:nodoc:
52
52
  # @file_handle = File.new( '/dev/null', 'w' )
53
53
  # end
54
54
  def setup( &block )
55
- compile!( :setup!, &block )
55
+ compile!(:setup!, &block)
56
56
  end
57
57
 
58
58
  # Define your write method with this helper.
@@ -62,7 +62,7 @@ module Yell #:nodoc:
62
62
  # @file_handle.puts event.message
63
63
  # end
64
64
  def write( &block )
65
- compile!( :write!, &block )
65
+ compile!(:write!, &block)
66
66
  end
67
67
 
68
68
  # Define your open method with this helper.
@@ -72,7 +72,7 @@ module Yell #:nodoc:
72
72
  # @stream = ::File.open( 'test.log', ::File::WRONLY|::File::APPEND|::File::CREAT )
73
73
  # end
74
74
  def open( &block )
75
- compile!( :open!, &block )
75
+ compile!(:open!, &block)
76
76
  end
77
77
 
78
78
  # Define your close method with this helper.
@@ -82,7 +82,7 @@ module Yell #:nodoc:
82
82
  # @stream.close
83
83
  # end
84
84
  def close( &block )
85
- compile!( :close!, &block )
85
+ compile!(:close!, &block)
86
86
  end
87
87
 
88
88
 
@@ -106,24 +106,24 @@ module Yell #:nodoc:
106
106
  m = instance_method( name )
107
107
 
108
108
  # Create a new method with leading underscore
109
- define_method( "_#{name}", &block )
110
- _m = instance_method( "_#{name}" )
111
- remove_method( "_#{name}" )
109
+ define_method("_#{name}", &block)
110
+ _m = instance_method("_#{name}")
111
+ remove_method("_#{name}")
112
112
 
113
113
  # Define instance method
114
- define!( name, _m, m, &block )
114
+ define!(name, _m, m, &block)
115
115
  end
116
116
 
117
117
  # Define instance method by given name and call the unbound
118
118
  # methods in order with provided block.
119
119
  def define!( name, _m, m, &block )
120
120
  if block.arity == 0
121
- define_method( name ) do
121
+ define_method(name) do
122
122
  _m.bind(self).call
123
123
  m.bind(self).call
124
124
  end
125
125
  else
126
- define_method( name ) do |*args|
126
+ define_method(name) do |*args|
127
127
  _m.bind(self).call(*args)
128
128
  m.bind(self).call(*args)
129
129
  end
@@ -180,7 +180,7 @@ module Yell #:nodoc:
180
180
  # Adapter classes should provide their own implementation
181
181
  # of this method (if applicable).
182
182
  def setup!( options )
183
- self.level = options[:level]
183
+ self.level = Yell.__fetch__(options,:level)
184
184
  end
185
185
 
186
186
  # Perform the actual write.
@@ -221,7 +221,7 @@ module Yell #:nodoc:
221
221
 
222
222
  # Get an array of inspected attributes for the adapter.
223
223
  def inspectables
224
- [ :level ]
224
+ [:level]
225
225
  end
226
226
 
227
227
  end
@@ -54,12 +54,12 @@ module Yell #:nodoc:
54
54
 
55
55
  # @overload setup!( options )
56
56
  def setup!( options )
57
- self.header = options.fetch(:header, true)
58
- self.date_pattern = options.fetch(:date_pattern, DefaultDatePattern)
59
- self.keep = options.fetch(:keep, false)
60
- self.symlink = options.fetch(:symlink, true)
57
+ self.header = Yell.__fetch__(options, :header, :default => true)
58
+ self.date_pattern = Yell.__fetch__(options, :date_pattern, :default => DefaultDatePattern)
59
+ self.keep = Yell.__fetch__(options, :keep, :default => false)
60
+ self.symlink = Yell.__fetch__(options, :symlink, :default => true)
61
61
 
62
- @original_filename = ::File.expand_path options.fetch(:filename, default_filename)
62
+ @original_filename = ::File.expand_path(Yell.__fetch__(options, :filename, :default => default_filename))
63
63
  options[:filename] = @original_filename
64
64
 
65
65
  @date = Time.now
@@ -86,7 +86,7 @@ module Yell #:nodoc:
86
86
 
87
87
  # @overload close!
88
88
  def close!
89
- @filename = filename_for( @date )
89
+ @filename = filename_for(@date)
90
90
 
91
91
  super
92
92
  end
@@ -117,7 +117,7 @@ module Yell #:nodoc:
117
117
  # it makes the best guess by checking the last access time (which may result
118
118
  # in false cleanups).
119
119
  def cleanup!
120
- files = Dir[ @original_filename.sub( /(\.\w+)?$/, ".*\\1" ) ].sort.select do |file|
120
+ files = Dir[ @original_filename.sub(/(\.\w+)?$/, ".*\\1") ].sort.select do |file|
121
121
  _, pattern = header_from(file)
122
122
 
123
123
  # Select if the date pattern is nil (no header info available within the file) or
@@ -140,14 +140,16 @@ module Yell #:nodoc:
140
140
  # do nothing, because symlink is already correct
141
141
  return if ::File.symlink?(@original_filename) && ::File.readlink(@original_filename) == @filename
142
142
 
143
- ::File.unlink( @original_filename ) if ::File.exist?( @original_filename )
144
- ::File.symlink( @filename, @original_filename )
143
+ ::File.unlink(@original_filename) if ::File.exist?(@original_filename)
144
+ ::File.symlink(@filename, @original_filename)
145
145
  end
146
146
 
147
147
  # Symlink the original filename?
148
148
  #
149
149
  # @return [Boolean] true or false
150
- def symlink?; !!symlink; end
150
+ def symlink?
151
+ !!symlink
152
+ end
151
153
 
152
154
  # Write the header information into the file
153
155
  def header!
@@ -157,24 +159,26 @@ module Yell #:nodoc:
157
159
  # Write header into the file?
158
160
  #
159
161
  # @return [Boolean] true or false
160
- def header?; !!header; end
162
+ def header?
163
+ !!header
164
+ end
161
165
 
162
166
  # Sets the filename with the `:date_pattern` appended to it.
163
167
  def filename_for( date )
164
- @original_filename.sub( /(\.\w+)?$/, ".#{date.strftime(date_pattern)}\\1" )
168
+ @original_filename.sub(/(\.\w+)?$/, ".#{date.strftime(date_pattern)}\\1")
165
169
  end
166
170
 
167
171
  # Fetch the header form the file
168
172
  def header_from( file )
169
- if m = ::File.open( file, &:readline ).match( HeaderRegexp )
173
+ if m = ::File.open(file, &:readline).match(HeaderRegexp)
170
174
  # in case there is a Header present, we can just read from it
171
- [ Time.at( m[2].to_f ), m[3] ]
175
+ [ Time.at(m[2].to_f), m[3] ]
172
176
  else
173
177
  # In case there is no header: we need to take a good guess
174
178
  #
175
179
  # Since the pattern can not be determined, we will just return the Posix ctime.
176
180
  # That is NOT the creatint time, so the value will potentially be wrong!
177
- [ ::File.ctime(file), nil ]
181
+ [::File.ctime(file), nil]
178
182
  end
179
183
  end
180
184
 
@@ -11,14 +11,14 @@ module Yell #:nodoc:
11
11
 
12
12
  # @overload setup!( options )
13
13
  def setup!( options )
14
- @filename = ::File.expand_path options.fetch(:filename, default_filename)
14
+ @filename = ::File.expand_path(Yell.__fetch__(options, :filename, :default => default_filename))
15
15
 
16
16
  super
17
17
  end
18
18
 
19
19
  # @overload open!
20
20
  def open!
21
- @stream = ::File.open( @filename, ::File::WRONLY|::File::APPEND|::File::CREAT )
21
+ @stream = ::File.open(@filename, ::File::WRONLY|::File::APPEND|::File::CREAT)
22
22
 
23
23
  super
24
24
  end
@@ -26,7 +26,7 @@ module Yell #:nodoc:
26
26
  def default_filename #:nodoc:
27
27
  logdir = ::File.expand_path("log")
28
28
 
29
- ::File.expand_path ::File.directory?(logdir) ? "#{logdir}/#{Yell.env}.log" : "#{Yell.env}.log"
29
+ ::File.expand_path(::File.directory?(logdir) ? "#{logdir}/#{Yell.env}.log" : "#{Yell.env}.log")
30
30
  end
31
31
 
32
32
  end
@@ -45,9 +45,9 @@ module Yell #:nodoc:
45
45
  def setup!( options )
46
46
  @stream = nil
47
47
 
48
- self.colors = options.fetch(:colors, false)
49
- self.formatter = options.fetch(:format, options[:formatter])
50
- self.sync = options.fetch(:sync, true)
48
+ self.colors = Yell.__fetch__(options, :colors, :default => false)
49
+ self.formatter = Yell.__fetch__(options, :format, :formatter)
50
+ self.sync = Yell.__fetch__(options, :sync, :default => true)
51
51
 
52
52
  super
53
53
  end
@@ -68,15 +68,15 @@ module Yell #:nodoc:
68
68
 
69
69
  # @overload open!
70
70
  def open!
71
- @stream.sync = self.sync if @stream.respond_to? :sync
72
- @stream.flush if @stream.respond_to? :flush
71
+ @stream.sync = self.sync if @stream.respond_to?(:sync)
72
+ @stream.flush if @stream.respond_to?(:flush)
73
73
 
74
74
  super
75
75
  end
76
76
 
77
77
  # @overload close!
78
78
  def close!
79
- @stream.close if @stream.respond_to? :close
79
+ @stream.close if @stream.respond_to?(:close)
80
80
  @stream = nil
81
81
 
82
82
  super
@@ -53,16 +53,16 @@ module Yell #:nodoc:
53
53
  reset!
54
54
 
55
55
  # FIXME: :format is deprecated in future versions --R
56
- self.formatter = @options.fetch(:format, @options[:formatter])
57
- self.level = @options.fetch(:level, 0)
58
- self.name = @options.fetch(:name, nil)
59
- self.trace = @options.fetch(:trace, :error)
56
+ self.formatter = Yell.__fetch__(@options, :format, :formatter)
57
+ self.level = Yell.__fetch__(@options, :level, :default => 0)
58
+ self.name = Yell.__fetch__(@options, :name)
59
+ self.trace = Yell.__fetch__(@options, :trace, :default => :error)
60
60
 
61
61
  # silencer
62
- self.silence(*@options[:silence]) if @options.key?(:silence)
62
+ self.silence(*Yell.__fetch__(@options, :silence))
63
63
 
64
64
  # adapters may be passed in the options
65
- extract!(*@options[:adapters]) if @options.key?(:adapters)
65
+ extract!(*Yell.__fetch__(@options, :adapters))
66
66
 
67
67
  # extract adapter
68
68
  self.adapter(args.pop) if args.any?
@@ -35,7 +35,7 @@ module Yell #:nodoc:
35
35
  # @raise [Yell::LoggerNotFound] Raised when repository does not have that key
36
36
  # @return [Yell::Logger] The logger instance
37
37
  def self.[]( name )
38
- synchronize { instance.fetch(name) or raise Yell::LoggerNotFound.new(name) }
38
+ synchronize { instance.__fetch__(name) or raise Yell::LoggerNotFound.new(name) }
39
39
  end
40
40
 
41
41
  # Get the list of all loggers in the repository
@@ -57,11 +57,11 @@ module Yell #:nodoc:
57
57
  # If the logger could not be found and has a superclass, it
58
58
  # will attempt to look there. This is important for the
59
59
  # Yell::Loggable module.
60
- def fetch( name )
60
+ def __fetch__( name )
61
61
  logger = loggers[name] || loggers[name.to_s]
62
62
 
63
63
  if logger.nil? && name.respond_to?(:superclass)
64
- return fetch(name.superclass)
64
+ return __fetch__(name.superclass)
65
65
  end
66
66
 
67
67
  logger
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Yell #:nodoc:
4
- VERSION = "2.0.0"
4
+ VERSION = "2.0.1"
5
5
 
6
6
  end
7
7
 
@@ -1,12 +1,16 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
- require 'active_support'
3
+
4
+ begin
5
+ require 'active_support'
6
+ rescue LoadError
7
+ end
4
8
 
5
9
  # make a setup just like in railties ~> 4.0.0
6
10
  #
7
11
  # We simulate the case when Rails 4 starts up its server
8
12
  # and wants to append the log output.
9
- describe "Compatibility to ActiveSupport::Logger" do
13
+ describe "Compatibility to ActiveSupport::Logger", pending: (!defined?(ActiveSupport) || ActiveSupport::VERSION::MAJOR < 4) do
10
14
 
11
15
  let!(:yell) { Yell.new($stdout, :format => "%m") }
12
16
 
@@ -24,7 +24,7 @@ describe Yell do
24
24
  end
25
25
 
26
26
  context ".load!" do
27
- subject { Yell.load!( 'yell.yml' ) }
27
+ subject { Yell.load!('yell.yml') }
28
28
 
29
29
  before do
30
30
  mock(Yell::Configuration).load!('yell.yml') { {} }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yell
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rudolf Schmidt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-04 00:00:00.000000000 Z
11
+ date: 2013-12-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Yell - Your Extensible Logging Library. Define multiple adapters, various
14
14
  log level combinations or message formatting options like you've never done before