1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

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
This commit is contained in:
John Mair 2012-04-13 14:55:30 +12:00
parent 5fbb3076f1
commit b06e9dd9ae
2 changed files with 24 additions and 3 deletions

View file

@ -3,10 +3,19 @@ class Pry
FindMethod = Pry::CommandSet.new do FindMethod = Pry::CommandSet.new do
create_command "find-method" do create_command "find-method" do
extend Helpers::BaseHelpers
group "Context" 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]" 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) def options(opti)
opti.on :n, :name, "Search for a method by name" opti.on :n, :name, "Search for a method by name"
opti.on :c, :content, "Search for a method based on content in Regex form" opti.on :c, :content, "Search for a method based on content in Regex form"
@ -36,7 +45,7 @@ class Pry
else else
puts text.bold("Methods Matched") puts text.bold("Methods Matched")
puts "--" puts "--"
puts to_put stagger_output to_put.join("\n")
end end
end end
@ -67,7 +76,11 @@ class Pry
end end
end end
klass.constants.each do |klazz| klass.constants.each do |klazz|
begin
meths += ((res = content_search(pattern, klass.const_get(klazz), current, the_methods)) ? res : []) meths += ((res = content_search(pattern, klass.const_get(klazz), current, the_methods)) ? res : [])
rescue Pry::RescuableException
next
end
end end
return meths.uniq.flatten return meths.uniq.flatten
end end

View file

@ -110,6 +110,14 @@ class Pry
RbConfig::CONFIG['ruby_install_name'] == 'rbx' RbConfig::CONFIG['ruby_install_name'] == 'rbx'
end 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. # a simple pager for systems without `less`. A la windows.
def simple_pager(text, output=output()) def simple_pager(text, output=output())
text_array = text.lines.to_a text_array = text.lines.to_a