Browse files

find-command uses ruby18_source_location on 1.8

* also now using stagger_output to page long output
* made more robust by rescuing/ignoring exceptions generated by stupid constant auto-loading
  • Loading branch information...
1 parent 5fbb307 commit b06e9dd9ae2cb4bd1fd34a769f940389d301f6de @banister banister committed Apr 13, 2012
Showing with 24 additions and 3 deletions.
  1. +15 −2 lib/pry/default_commands/find_method.rb
  2. +9 −1 lib/pry/helpers/base_helpers.rb
View
17 lib/pry/default_commands/find_method.rb
@@ -3,10 +3,19 @@ module DefaultCommands
FindMethod = Pry::CommandSet.new do
create_command "find-method" do
+ extend Helpers::BaseHelpers
+
group "Context"
+ options :requires_gem => "ruby18_source_location" if mri_18?
+
description "Recursively search for a method within a Class/Module or the current namespace. find-method [-n | -c] METHOD [NAMESPACE]"
+
+ def setup
+ require 'ruby18_source_location' if mri_18?
+ end
+
def options(opti)
opti.on :n, :name, "Search for a method by name"
opti.on :c, :content, "Search for a method based on content in Regex form"
@@ -36,7 +45,7 @@ def process
else
puts text.bold("Methods Matched")
puts "--"
- puts to_put
+ stagger_output to_put.join("\n")
end
end
@@ -67,7 +76,11 @@ def content_search(pattern, klass, current=[], the_methods=[])
end
end
klass.constants.each do |klazz|
- meths += ((res = content_search(pattern, klass.const_get(klazz), current, the_methods)) ? res : [])
+ begin
+ meths += ((res = content_search(pattern, klass.const_get(klazz), current, the_methods)) ? res : [])
+ rescue Pry::RescuableException
+ next
+ end
end
return meths.uniq.flatten
end
View
10 lib/pry/helpers/base_helpers.rb
@@ -110,6 +110,14 @@ def rbx?
RbConfig::CONFIG['ruby_install_name'] == 'rbx'
end
+ def mri_18?
+ RUBY_VERSION =~ /1.8/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
+ end
+
+ def mri_19?
+ RUBY_VERSION =~ /1.9/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
+ end
+
# a simple pager for systems without `less`. A la windows.
def simple_pager(text, output=output())
text_array = text.lines.to_a
@@ -138,7 +146,7 @@ def stagger_output(text, out = nil)
# Sys.
$stdout
end
-
+
if text.lines.count < page_size || !Pry.pager
out.puts text
return

0 comments on commit b06e9dd

Please sign in to comment.