Class: Mongo::Rails::Instrumentation::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/mongo/rails/instrumentation/railtie.rb

Instance Method Summary collapse

Instance Method Details

#instrument(clazz, methods) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mongo/rails/instrumentation/railtie.rb', line 19

def instrument(clazz, methods)
  clazz.module_eval do
    methods.each do |m|
      class_eval <<-CODE, __FILE__, __LINE__ + 1
        def #{m}_with_instrumentation(*args, &block)
          ActiveSupport::Notifications.instrumenter.instrument "mongo.mongo", :name => "#{m}" do
            #{m}_without_instrumentation(*args, &block)
          end
        end
      CODE

      alias_method_chain m, :instrumentation
    end
  end
end