Created
July 18, 2013 09:01
-
-
Save mipearson/6027857 to your computer and use it in GitHub Desktop.
Wrap methods in rack-mini-profiler steps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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