Class: Rack::Metrics::Instrumenter

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/metrics/instrumenter.rb

Class Method Summary collapse

Class Method Details

.instrument_method(klass, method, name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rack/metrics/instrumenter.rb', line 4

def self.instrument_method(klass, method, name)
  method_name = method.to_s.gsub(/[\?\!]/, "")
  with_rack_metrics =  ("#{method_name}_with_rack_metrics").to_sym
  without_rack_metrics = ("#{method_name}_without_rack_metrics").to_sym
  klass.send :alias_method, without_rack_metrics, method
  klass.send :define_method, with_rack_metrics do |*args, &orig|
    ActiveSupport::Notifications.instrument(name)
    self.send without_rack_metrics, *args, &orig
  end
  klass.send :alias_method, method, with_rack_metrics
end