Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/zookeeper/core_ext.rb

Overview

this is borrowed from the excellent Logging gem: github.com/TwP/logging

Instance Method Summary collapse

Instance Method Details

#_zk_logger_nameObject

Returns a predictable logger name for the current module or class. If used within an anonymous class, the first non-anonymous class name will be used as the logger name. If used within a meta-class, the name of the actual class will be used as the logger name. If used within an anonymous module, the string ‘anonymous’ will be returned.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zookeeper/core_ext.rb', line 39

def _zk_logger_name
  return name unless name.nil? or name.empty?

  # check if this is a metaclass (or eigenclass)
  if ancestors.include? Class
    inspect =~ %r/#<Class:([^#>]+)>/
    return $1
  end

  # see if we have a superclass
  if respond_to? :superclass
    return superclass.logger_name
  end

  # we are an anonymous module
  return 'anonymous'
end