From 54a4065074485ece05c4fe598d16d108cb292d88 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 25 Jul 2014 13:06:22 -0500 Subject: Optionally add String extensions for ruby-prof printer option [ci skip] --- tools/profile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tools') diff --git a/tools/profile b/tools/profile index 5c916aafc8..62daa2f0bd 100755 --- a/tools/profile +++ b/tools/profile @@ -84,6 +84,32 @@ module CodeTools end end end +# ruby-prof printer name causes the third arg to be sent :classify +# which is probably overkill if you already know the name of the ruby-prof +# printer you want to use, e.g. Graph +begin + require 'active_support/inflector' + require 'active_support/core_ext/string/inflections' +rescue LoadError + STDERR.puts $!.message + class String + # File activesupport/lib/active_support/inflector/methods.rb, line 150 + def classify + # strip out any leading schema name + camelize(self.sub(/.*\./, '')) + end + # File activesupport/lib/active_support/inflector/methods.rb, line 68 + def camelize(uppercase_first_letter = true) + string = self + if uppercase_first_letter + string = string.sub(/^[a-z\d]*/) { $&.capitalize } + else + string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } + end + string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') + end + end +end if $0 == __FILE__ if (filename = ARGV.shift) path = File.expand_path(filename) -- cgit v1.2.3