Skip to content

Instantly share code, notes, and snippets.

@mipearson
Created July 18, 2013 09:01
Show Gist options
  • Save mipearson/6027857 to your computer and use it in GitHub Desktop.
Save mipearson/6027857 to your computer and use it in GitHub Desktop.
Wrap methods in rack-mini-profiler steps
# Usage:
# class MyClass
# extend MiniProfilerInstrumenter
#
# def my_slow_method
# ...
# end
# instrument_method :my_slow_method
module MiniProfilerInstrumenter
def instrument_method method_name
alias_method "#{method_name}_without_instrument", method_name
define_method "#{method_name}_with_instrument" do |*args|
Rack::MiniProfiler.step("#{self.class}##{method_name}") do
send("#{method_name}_without_instrument", *args)
end
end
alias_method method_name, "#{method_name}_with_instrument"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment