show-method and show-doc now accept multiple method names

fixes
This commit is contained in:
Gosha Arinich 2011-08-27 17:13:15 +03:00
parent 0e119555de
commit 2b70a27f1f
5 changed files with 72 additions and 41 deletions

View File

@ -11,7 +11,7 @@ class Pry
target = target()
opts = Slop.parse!(args) do |opt|
opt.banner = "Usage: show-doc [OPTIONS] [METH]\n" \
opt.banner = "Usage: show-doc [OPTIONS] [METH 1] [METH 2] [METH N]\n" \
"Show the comments above method METH. Tries instance methods first and then methods by default.\n" \
"e.g show-doc hello_method"
@ -28,25 +28,28 @@ class Pry
next if opts.help?
meth_name = args.shift
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help"
next
end
args = [nil] if args.empty?
args.each do |method_name|
meth_name = method_name
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help"
next
end
doc, code_type = doc_and_code_type_for(meth)
next if !doc
doc, code_type = doc_and_code_type_for(meth)
next if !doc
next output.puts("No documentation found.") if doc.empty?
doc = process_comment_markup(doc, code_type)
output.puts make_header(meth, code_type, doc)
output.puts "#{text.bold("visibility: ")} #{method_visibility(meth).to_s}"
if meth.respond_to?(:parameters)
output.puts "#{text.bold("signature: ")} #{signature_for(meth)}"
output.puts
next output.puts("No documentation found.") if doc.empty?
doc = process_comment_markup(doc, code_type)
output.puts make_header(meth, code_type, doc)
output.puts "#{text.bold("visibility: ")} #{method_visibility(meth).to_s}"
if meth.respond_to?(:parameters)
output.puts "#{text.bold("signature: ")} #{signature_for(meth)}"
output.puts
end
render_output(opts.flood?, false, doc)
doc
end
render_output(opts.flood?, false, doc)
doc
end
alias_command "?", "show-doc", ""

View File

@ -9,7 +9,7 @@ class Pry
target = target()
opts = Slop.parse!(args) do |opt|
opt.banner "Usage: show-method [OPTIONS] [METH]\n" \
opt.banner "Usage: show-method [OPTIONS] [METH 1] [METH 2] [METH N]\n" \
"Show the source for method METH. Tries instance methods first and then methods by default.\n" \
"e.g: show-method hello_method"
@ -29,30 +29,33 @@ class Pry
next if opts.help?
meth_name = args.shift
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help"
next
args = [nil] if args.empty?
args.each do |method_name|
meth_name = method_name
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help"
next
end
code, code_type = code_and_code_type_for(meth)
next if !code
output.puts make_header(meth, code_type, code)
if Pry.color
code = CodeRay.scan(code, code_type).term
end
start_line = false
if opts.l?
start_line = meth.source_location ? meth.source_location.last : 1
end
start_line = opts.b? ? 1 : start_line
render_output(opts.flood?, start_line, code)
code
end
code, code_type = code_and_code_type_for(meth)
next if !code
output.puts make_header(meth, code_type, code)
if Pry.color
code = CodeRay.scan(code, code_type).term
end
start_line = false
if opts.l?
start_line = meth.source_location ? meth.source_location.last : 1
end
start_line = opts.b? ? 1 : start_line
render_output(opts.flood?, start_line, code)
code
end
alias_command "show-source", "show-method", ""

View File

@ -32,6 +32,11 @@ def sample_method
:sample
end
# another sample doc
def another_sample_method
:another_sample
end
def redirect_pry_io(new_in, new_out)
old_in = Pry.input
old_out = Pry.output

View File

@ -10,6 +10,16 @@ describe "Pry::DefaultCommands::Documentation" do
str_output.string.should =~ /sample doc/
end
it 'should output multiple methods\' documentation' do
str_output = StringIO.new
redirect_pry_io(InputTester.new("show-doc sample_method another_sample_method", "exit-all"), str_output) do
pry
end
str_output.string.should =~ /sample doc/
str_output.string.should =~ /another sample doc/
end
it 'should output a method\'s documentation if inside method without needing to use method name' do
$str_output = StringIO.new

View File

@ -10,6 +10,16 @@ describe "Pry::DefaultCommands::Introspection" do
str_output.string.should =~ /def sample/
end
it 'should output multiple methods\' sources' do
str_output = StringIO.new
redirect_pry_io(InputTester.new("show-method sample_method another_sample_method", "exit-all"), str_output) do
pry
end
str_output.string.should =~ /def sample/
str_output.string.should =~ /def another_sample/
end
it 'should output a method\'s source with line numbers' do
str_output = StringIO.new