Module: Lug::Extend::Class

Defined in:
lib/lug/extend.rb

Instance Method Summary collapse

Instance Method Details

#logger_on(namespace) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lug/extend.rb', line 12

def logger_on(namespace)
  cap_ns = namespace.to_s.split(':').map(&:capitalize).join
  mod_name = :"LoggerOn#{cap_ns}"

  return const_get(mod_name) if const_defined?(mod_name)
  return unless LUG

  mod = Module.new
  mod.module_eval(%(
    module ClassMethods
      def logger
        LUG.on(#{namespace.inspect})
      end
    end

    def self.included(receiver)
      receiver.extend(ClassMethods)
    end

    def logger
      self.class.logger
    end
  ))
  const_set(mod_name, mod)

  include mod
end