module Method::Tracer::ClassMethods

Public Instance Methods

guess_class_name() click to toggle source
# File lib/method/tracer.rb, line 52
def guess_class_name
  return self.name if self.name && !self.name.empty?
  self.to_s
end
trace_method(*methods) click to toggle source
# File lib/method/tracer.rb, line 57
def trace_method(*methods)
  methods.each do |method_name|
    method_name_without_instrumentation = "#{method_name}_without_instrumentation".to_sym
    class_name = guess_class_name
    class_eval do
      alias_method method_name_without_instrumentation, method_name

      define_method(method_name) do |*args, &block|
        ::Method::Tracer.trace_method(class_name, method_name) do
          send(method_name_without_instrumentation, *args, &block)
        end
      end
    end
  end
end