Module: CallLogger::ClassMethods

Defined in:
lib/call_logger.rb

Instance Method Summary collapse

Instance Method Details

#do_log(method, args, &block) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/call_logger.rb', line 43

def do_log(method, args, &block)
  logger = ::CallLogger.configuration.logger
  formatter = ::CallLogger.configuration.formatter
  method_wrapper = ::CallLogger::MethodWrapper.new(
    logger: logger, formatter: formatter
  )
  method_wrapper.call(method, args, &block)
end

#log(method) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/call_logger.rb', line 25

def log(method)
  alias_method "#{method}_without_log", method
  define_method method do |*args|
    self.class.do_log("#{self.class}##{method}", args) do
      send("#{method}_without_log", *args)
    end
  end
end

#log_class(method) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/call_logger.rb', line 34

def log_class(method)
  singleton_class.alias_method "#{method}_without_log", method
  singleton_class.define_method method do |*args|
    do_log("#{self}.#{method}", args) do
      send("#{method}_without_log", *args)
    end
  end
end