Module: Lumber::InheritanceRegistry

Extended by:
InheritanceRegistry, MonitorMixin
Included in:
InheritanceRegistry
Defined in:
lib/lumber/inheritance_registry.rb

Instance Method Summary collapse

Instance Method Details

#[](class_name) ⇒ Object


15
16
17
18
19
# File 'lib/lumber/inheritance_registry.rb', line 15

def [](class_name)
  synchronize do
    @mapping[class_name]
  end
end

#[]=(class_name, logger_fullname) ⇒ Object


9
10
11
12
13
# File 'lib/lumber/inheritance_registry.rb', line 9

def []=(class_name, logger_fullname)
  synchronize do
    @mapping[class_name] = logger_fullname
  end
end

#clearObject


21
22
23
24
25
# File 'lib/lumber/inheritance_registry.rb', line 21

def clear
  synchronize do
    @mapping.clear
  end
end

#find_registered_logger(clazz) ⇒ Object


27
28
29
30
31
32
33
# File 'lib/lumber/inheritance_registry.rb', line 27

def find_registered_logger(clazz)
  synchronize do
    return nil unless clazz
    logger_name = self[clazz.name]
    logger_name || find_registered_logger(clazz.superclass)
  end
end

#register_inheritance_handlerObject

Adds a inheritance handler to Object so we can add loggers for registered classes


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/lumber/inheritance_registry.rb', line 52

def register_inheritance_handler
  synchronize do

    return if defined?(Object.inherited_with_lumber_registry)

    Object.class_eval do

      class << self

        def inherited_with_lumber_registry(subclass)
          inherited_without_lumber_registry(subclass)

          # Add a logger to 'subclass' if it is directly in the registry
          # No need to check full inheritance chain LoggerSupport handles it
          # Also prevent rails from subsequently overriding our logger when rails
          # is loaded after registering logger inheritance
          if Lumber::InheritanceRegistry[subclass.name]
            subclass.send(:include, Lumber.logger_concern)
          end
        end

        alias_method_chain :inherited, :lumber_registry

      end

    end

  end
end

#remove_inheritance_handlerObject


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lumber/inheritance_registry.rb', line 35

def remove_inheritance_handler
  synchronize do

    return unless defined?(Object.inherited_with_lumber_registry)

    Object.class_eval do
      class << self
        remove_method :inherited_with_lumber_registry
        remove_method :inherited
        alias_method :inherited, :inherited_without_lumber_registry
      end
    end

  end
end