Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bug/speedtracer/duck-puncher.rb

Instance Method Summary collapse

Instance Method Details

#build_tracing_wrappers(context, *methods) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rack/bug/speedtracer/duck-puncher.rb', line 64

def build_tracing_wrappers(context, *methods)
  @traced ||= {}

  Rack::Bug::SpeedTracer::safe_method_names(self, methods).each do |method_name, old_method|
    next if @traced.has_key?(method_name)
    @traced[method_name] = true

    alias_method old_method, method_name

    self.class_eval "    def \#{method_name}(*args, &block)\n      trace_run(\"\#{context}\", caller(0)[0], args) do\n        \#{old_method}(*args, &block)\n      end\n    end\n    EOC\n  end\nend\n", __FILE__, __LINE__

#trace_class_methods(*methods_names) ⇒ Object



56
57
58
# File 'lib/rack/bug/speedtracer/duck-puncher.rb', line 56

def trace_class_methods(*methods_names)
  (class << self; self; end).build_tracing_wrappers('#{self.name}::', *methods_names)
end

#trace_methods(*methods) ⇒ Object



60
61
62
# File 'lib/rack/bug/speedtracer/duck-puncher.rb', line 60

def trace_methods(*methods)
  build_tracing_wrappers('#{self.class.name}#', *methods)
end