Last active
August 29, 2015 14:21
-
-
Save brenes/4bf96793d13d62015f08 to your computer and use it in GitHub Desktop.
Utility class for decorating a method and adding the information to the rach mini profiler summary
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
# Simple class to decorate a method and send information MiniProfiler | |
# Usage: CustomMiniProfiler.measure MyClass, :mymethod, "This method takes..." | |
class CustomMiniProfiler | |
def self.measure klass, method, message, class_method=false | |
receptor_class = class_method ? klass.singleton_class : klass | |
receptor_class.send :define_method, "#{method}_with_mini_profiler" do |*args, &block| | |
Rack::MiniProfiler.step(message) do | |
send "#{method}_without_mini_profiler", *args, &block | |
end | |
end | |
receptor_class.send :alias_method, "#{method}_without_mini_profiler", method | |
receptor_class.send :alias_method, method, "#{method}_with_mini_profiler" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment