logging 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.9.2 / 2008-09-03
2
+
3
+ 2 bug fixes
4
+ - Properly generates logger names for anonymous classes and
5
+ modules and meta-classes
6
+ - Fixed the rescue clause when 'turn' cannot be required
7
+
1
8
  == 0.9.1 / 2008-08-14
2
9
 
3
10
  1 minor enhancement
data/Rakefile CHANGED
@@ -16,11 +16,13 @@ PROJ.rdoc.dir = 'doc/rdoc'
16
16
  #PROJ.rdoc.remote_dir = 'rdoc'
17
17
  PROJ.rdoc.remote_dir = ''
18
18
  PROJ.version = Logging::VERSION
19
- PROJ.release_name = %q{Green Eggs & Ham}
19
+ PROJ.release_name = %q{Meta Class Madness}
20
20
 
21
21
  PROJ.exclude << %w[^tags$ ^tasks/archive ^coverage]
22
22
  PROJ.rdoc.exclude << '^data'
23
- PROJ.svn.path = ''
23
+
24
+ PROJ.ann.email[:server] = 'smtp.gmail.com'
25
+ PROJ.ann.email[:port] = 587
24
26
 
25
27
  depend_on 'flexmock'
26
28
  depend_on 'lockfile'
data/lib/logging.rb CHANGED
@@ -10,7 +10,7 @@ unless defined? Logging
10
10
  module Logging
11
11
 
12
12
  # :stopdoc:
13
- VERSION = '0.9.1'
13
+ VERSION = '0.9.2'
14
14
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
15
15
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
16
16
  WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM
@@ -170,8 +170,8 @@ module Logging
170
170
  when :root, 'root'; :root
171
171
  when String; key
172
172
  when Symbol; key.to_s
173
- when Module; key.name
174
- when Object; key.class.name
173
+ when Module; key.logger_name
174
+ when Object; key.class.logger_name
175
175
  end
176
176
  end
177
177
 
data/lib/logging/utils.rb CHANGED
@@ -45,8 +45,8 @@ class String
45
45
  # call-seq:
46
46
  # reduce( width, ellipses = '...' ) #=> string
47
47
  #
48
- # Reduce the size of the current string to the given _width_ by remove
49
- # characters from the middle of ths tring and replacing them with
48
+ # Reduce the size of the current string to the given _width_ by removing
49
+ # characters from the middle of the string and replacing them with
50
50
  # _ellipses_. If the _width_ is greater than the length of the string, the
51
51
  # string is returned unchanged. If the _width_ is less than the length of
52
52
  # the _ellipses_, then the _ellipses_ are returned.
@@ -69,4 +69,37 @@ class String
69
69
  end
70
70
  end
71
71
 
72
+ class Module
73
+
74
+ # call-seq:
75
+ # logger_name #=> string
76
+ #
77
+ # Returns a predictable logger name for the current module or class. If
78
+ # used within an anonymous class, the first non-anonymous class name will
79
+ # be used as the logger name. If used within a meta-class, the name of the
80
+ # actual class will be used as the logger name. If used within an
81
+ # anonymous module, the string 'anonymous' will be returned.
82
+ #
83
+ def logger_name
84
+ return name unless name.empty?
85
+
86
+ # check if this is a metaclass (or eigenclass)
87
+ if ancestors.include? Class
88
+ inspect =~ %r/#<Class:([^#>]+)>/
89
+ return $1
90
+ end
91
+
92
+ # see if we have a superclass
93
+ if respond_to? :superclass
94
+ return superclass.logger_name
95
+ end
96
+
97
+ # we are an anonymous module
98
+ ::Logging.log_internal(-2) {
99
+ 'cannot return a predictable, unique name for anonymous modules'
100
+ }
101
+ return 'anonymous'
102
+ end
103
+ end
104
+
72
105
  # EOF
data/test/setup.rb CHANGED
@@ -8,7 +8,9 @@ require 'rubygems'
8
8
  require 'test/unit'
9
9
  require 'fileutils'
10
10
  require 'stringio'
11
- require 'turn' rescue nil
11
+ begin
12
+ require 'turn'
13
+ rescue LoadError; end
12
14
 
13
15
  # This line is needed for Ruby 1.9 -- hashes throw a "KeyError" in 1.9
14
16
  # whereas they throw an "IndexError" in 1.8
data/test/test_utils.rb CHANGED
@@ -84,6 +84,30 @@ module TestLogging
84
84
  assert_equal '##', r
85
85
  end
86
86
 
87
+ def test_logger_name
88
+ assert_equal 'Array', Array.logger_name
89
+
90
+ c = Class.new(Array)
91
+ assert_equal '', c.name
92
+ assert_equal 'Array', c.logger_name
93
+
94
+ meta = class << Array; self; end
95
+ assert_equal '', meta.name
96
+ assert_equal 'Array', meta.logger_name
97
+
98
+ m = Module.new
99
+ assert_equal '', m.name
100
+ assert_equal 'anonymous', m.logger_name
101
+
102
+ c = Class.new(::Logging::Logger)
103
+ assert_equal '', c.name
104
+ assert_equal 'Logging::Logger', c.logger_name
105
+
106
+ meta = class << ::Logging::Logger; self; end
107
+ assert_equal '', meta.name
108
+ assert_equal 'Logging::Logger', meta.logger_name
109
+ end
110
+
87
111
  end # class TestUtils
88
112
  end # module TestLogging
89
113
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-14 00:00:00 -06:00
12
+ date: 2008-09-03 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency