Skip to content

Instantly share code, notes, and snippets.

@brenes
Last active August 29, 2015 14:21
Show Gist options
  • Save brenes/4bf96793d13d62015f08 to your computer and use it in GitHub Desktop.
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
# 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