aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorBenjamin Fleischer <github@benjaminfleischer.com>2014-07-25 13:06:22 -0500
committerBenjamin Fleischer <github@benjaminfleischer.com>2014-07-25 13:41:18 -0500
commit54a4065074485ece05c4fe598d16d108cb292d88 (patch)
tree52d6b00eb53f25446027c0576aac12d31728dd90 /tools
parentf36c46754fa420343e7b01695f09e62293a40597 (diff)
downloadrails-54a4065074485ece05c4fe598d16d108cb292d88.tar.gz
rails-54a4065074485ece05c4fe598d16d108cb292d88.tar.bz2
rails-54a4065074485ece05c4fe598d16d108cb292d88.zip
Optionally add String extensions for ruby-prof printer option
[ci skip]
Diffstat (limited to 'tools')
-rwxr-xr-xtools/profile26
1 files changed, 26 insertions, 0 deletions
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)