Module: Method::Tracer::ClassMethods

Defined in:
lib/method/tracer.rb

Instance Method Summary collapse

Instance Method Details

#guess_class_nameObject



52
53
54
55
# 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) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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